@codecraftkit
Documentation
The useCometRequest is used to make api calls using Comet.
npm i @codecraftkit/use-comet-request
it can be imported from hooks.
import { useCometRequest } from "@codecraftkit/hooks";
or alone.
import { useCometRequest } from "@codecraftkit/use-comet-request";
In order to use this hook, first you must have Comet Configurated, as shown below in _app
folder
import { Comet as CometApi} from '@codecraftkit/helpers'// o import Comet from '@codecraftkit/comet'/*** Meteor Backend Connection*/global['Comet'] = CometApi({host: process.env.NEXT_PUBLIC_METEOR_BACKEND,ssl: process.env.NEXT_PUBLIC_METEOR_SSL,tokenKey: 'token'})
Usage example
const { data, call, loading, error } = useCometRequest('tasks.list')
You can pass an option object as an argument as well
When destructuring the result you can change the item's key names as shown below
const {data: tasks,call: getTasks,loading: loadingTasks,error: errorTasks} = useCometRequest('tasks.list', {method: "POST"})
path
String
yes
The path of the request
options
Object
no
api custom configuration
defaultValue
String
no
data default value
getRes
Boolean
no
get the complete "response" instead of the "response.data"
verbose
String
no
Show requests logs in the console
data
any
response of the requests
call
function
Function to execute the request, it receive the request params as arguments
loading
boolean
Request loading state
error
String
Response Error