Logo
Chakra-UIReactJsNext.JS
Head

@codecraftkit

Documentation

useCometRequest

Description#

The useCometRequest is used to make api calls using Comet.

Installation#

Code Example

npm i @codecraftkit/use-comet-request

Import#

it can be imported from hooks.

Code Example

import { useCometRequest } from "@codecraftkit/hooks";

or alone.

Code Example

import { useCometRequest } from "@codecraftkit/use-comet-request";

Configuration#

In order to use this hook, first you must have Comet Configurated, as shown below in _app folder

Code Example

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#

Usage example

Code Example

const { data, call, loading, error } = useCometRequest('tasks.list')

Another Example#

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

Code Example

const {
data: tasks,
call: getTasks,
loading: loadingTasks,
error: errorTasks
} = useCometRequest('tasks.list', {method: "POST"})

Arguments#

name

type

required

default

description

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

Results#

name

type

description

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