Use the bknd SDK for React
<App />
inside <ClientProvider />
, so that these hooks point to your bknd instance:
ClientProvider
.
useApi()
useApiQuery()
selector: (api: Api) => FetchPromise
The first parameter is a selector function that provides an Api instance and expects an
endpoint function to be returned.
options
: optional object that inherits from SWRConfiguration
enabled
: Determines whether this hook should trigger a fetch of the data or not.refine
: Optional refinement that is called after a response from the API has been
received. Useful to omit irrelevant data from the response (see example below).refine
function as well as revalidateOnFocus
(option from
SWRConfiguration
) so that our data keeps updating on window focus change.
useEntity()
DataApi
and returns CRUD options as parameters:
read
method will fetch a list
of entities instead of a single entry.
useEntityQuery([entity], [id?])
:
entity: string
: Specify the table name of the entityid?: number | string
: If an id given, it will fetch a single entry, otherwise a listcreate: (input: object)
: Create a new entryread: (query: Partial<RepoQuery> = {})
: If an id was given,
it returns a single item, otherwise a listupdate: (input: object, id?: number | string)
: If an id was given, the id parameter is
optional. Updates the given entry partially._delete: (id?: number | string)
: If an id was given, the id parameter is
optional. Deletes the given entry.useEntityQuery()
useEntity
around SWR
. The previous example would look like
this:
useEntityQuery
are conveniently wrapped around the mutate
function,
so you don’t have think about this: