Skip to main content

useQuery

moopsyClient.
useQuery
<BP.Plug>
(BP, params)
⚛ React Hook (Function)
<>
Type Arguments
BP.Plug:
Moopsy Blueprint Plug
()
Arguments
BP:
Moopsy Blueprint Constants
params:
Moopsy Blueprint ParamsType
=>
Returns
Interface
UseMoopsyQueryRetVal

UseMoopsyQueryRetVal
Interface
Methods / Properties
isLoadingboolean
isErrorboolean
errorMoopsyError | void
dataResponseType of BP.Plug | void
refresh()=> Promise<ResponseType of BP.Plug>

A query allows calls a Moopsy method as soon as it is run, as opposed to a mutation where the call is not made until the .call() handle is run

Usage

import { moopsyClient } from './your-moopsy-client';
import * as FooBP from '../blueprints/foo.ts';

const params: FooBP.Plug["params"] = { some: "data" };

const fooMutation = moopsyClient.useQuery<FooBP.Plug>(FooBP, params);

return (
<div>
{fooMutation.isLoading ?
<div>Loading...</div>
: fooMutation.isError ?
<div style={{ color: "red" }}>Error: {fooMutation.error.description}</div>
:
<div>Hello, {fooMutation.data.hello}!</div>
}
</div>
)