Skip to main content
Version: 4.5

<RestProvider />

Manages state, providing all context needed to use the hooks. Should be placed as high as possible in application tree as any usage of the hooks is only possible for components below the provider in the React tree.


import { RestProvider } from 'rest-hooks';
import ReactDOM from 'react-dom';

<App />

initialState?: State\<unknown>

type State<T> = Readonly<{
entities: Readonly<{ [k: string]: { [id: string]: T } | undefined }>;
results: Readonly<{ [url: string]: unknown | PK[] | PK | undefined }>;
meta: Readonly<{
[url: string]: { date: number; error?: Error; expiresAt: number };

Instead of starting with an empty cache, you can provide your own initial state. This can be useful for testing, or rehydrating the cache state when using server side rendering.