@codecraftkit
Documentation
The useTypeAHead is a hook that is used with the component FormField type "typeAHead" to handle the api call.
npm i @codecraftkit/usetypeahead
it can be imported from hooks.
import { useTypeAHead } from "@codecraftkit/hooks";
or alone.
import { useTypeAHead } from "@codecraftkit/usetypeahead";
This hook allows you to get the data and send it to the TypeAHead from Comet, api or graphql
Go to Type A Head Component page...
//useTypeAHead examples// cometconst [getUsers, loadingUsers, setLoadingUsers] =useTypeAHead({path: 'users.list})//gqlconst [getUsers, loadingUsers, setLoadingUsers] =useTypeAHead({QUERY: P_USER,collection: 'P_User',})//Component type A Head<FormFieldtype='typeAHead'name='userId'label='Description'loading={loadingUsers}handleLoading={setLoadingUsers}typeAHeadSearch={getUsers}withButton/>
const [getUsers, loadingUsers, setLoadingUsers] =useTypeAHead({QUERY: P_USER,collection: 'P_User',customSend:(search, itemId)=>{return {search: itemId || search}},customGet:(res)=> {return res.data[collection].items}})
path
String
no, unless you are using Comet or an api
The path where the TypeAHead will get the data
field
String
no
In the response the name of the object that contains the array, not pass this argument if the array is in the response root
QUERY
Graphql Query
no
The Query where to get the data using gql
collection
String
no
The name of the collection
getAllCometData
Boolean
no
return all response data
customSend
Function
no
Function that receive the search and itemId and returns the object to send through params
customGet
Function
no
Function that receive the response and returns in it inside the get call
queryOptions
Object
no
Options that can be customize in the useQuery hook in Query
get
Function
Function that return the response data
loading
boolean
Api call loading
setLoading
setState
Handle loading state
error
String
Response Error