React
#
OverviewThis page covers some of the tools in the Finch React library. That allows you to easily hook into a Finch API from a React component.
#
Reference#
FinchProviderFinchProvider
is a component that is used to provide the FinchClient to your React components, and all the hooks used in those components.
#
Propsclient
an instance of the FinchClient to be used by the components.
#
useQueryuseQuery
is a hook that allows you to easily query the Finch API from inside a React component. This hooks stores the result of the query and loading states of the query.
#
Parametersquery
the query to be executed.
options
an object that allows you to configure the behavior of the query, and also the variables.
options.variables
an object that contains the variables to be used in the query.
options.skip
if set to false, the query will not be executed, until true. Defaults: false
options.pollInterval
the interval in milliseconds to poll the query. If the value is 0 the query will not poll. Defaults: 0
options.poll
a boolean value that indicates if the query should be initially polled. This only needs to be used in conjunction with the pollInterval
option if you do not want to initially poll the query.
#
RefetchingIf you need to refetch the query, you can use the refetch
function returned from the useQuery
hook.
#
Invalidation of CacheIf you want to invalidate and refresh the cache of data in a query, instead of refetching you can use invalidation, which happens in the background. This is useful if you want to invalidate cache data based on some external event. A example of this is if you want to invalidate the cache when the focus of the window is returned to the browser.
This is just a basic example of how you can use the invalidate
function. You can use it in any way you want to invalidate the cache. We are planning to add some more advanced features that build on top of this, like window focus invalidation.
#
Polling ControlsThe useQuery hook has a few additional controls that allow you to control the polling behavior of the query.
startPolling
starts the polling of the query of it is not currently started.
stopPolling
stops the polling of the query of it is not currently stopped.