Installation
- NPM
- Yarn
yarn add @rest-hooks/react @rest-hooks/test @rest-hooks/hooks @rest-hooks/rest
npm install --save @rest-hooks/react @rest-hooks/test @rest-hooks/hooks @rest-hooks/rest
TypeScript is optional, but requires at least version 3.7 for full type enforcement.
Add provider at top-level component
- React Web 16+
- React Web 18+
- React Native
- NextJS
/index.tsx
import { CacheProvider } from '@rest-hooks/react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<CacheProvider>
<App />
</CacheProvider>,
document.body,
);
/index.tsx
import { CacheProvider } from '@rest-hooks/react';
import ReactDOM from 'react-dom';
ReactDOM.createRoot(document.body).render(
<CacheProvider>
<App />
</CacheProvider>,
);
/index.tsx
import { CacheProvider } from '@rest-hooks/react';
import { AppRegistry } from 'react-native';
const Root = () => (
<CacheProvider>
<App />
</CacheProvider>
);
AppRegistry.registerComponent('MyApp', () => Root);
npm install --save @rest-hooks/ssr @rest-hooks/redux redux
pages/_document.tsx
import { RestHooksDocument } from '@rest-hooks/ssr/nextjs';
export default RestHooksDocument;
pages/_app.tsx
import { AppCacheProvider } from '@rest-hooks/ssr/nextjs';
import type { AppProps } from 'next/app';
export default function App({ Component, pageProps }: AppProps) {
return (
<AppCacheProvider>
<Component {...pageProps} />
</AppCacheProvider>
);
}
Alternatively integrate state with redux
Legacy (IE) browser support
If you see Uncaught TypeError: Class constructor Resource cannot be invoked without 'new'
,
follow the instructions to add legacy browser support to packages