Skip to main content
Version: 7.0

useController()

function useController(): Controller;

Provides access to Controller which can be used for imperative control over the cache. For instance fetch, invalidate, and receive

import { useController } from '@rest-hooks/react';

function MyComponent({ id }) {
const { fetch, invalidate, resetEntireStore } = useController();

const handleRefresh = useCallback(
async e => {
await fetch(MyResource.get, { id });
},
[fetch, id],
);

const handleSuspend = useCallback(
async e => {
await invalidate(MyResource.get, { id });
},
[invalidate, id],
);

const handleLogout = useCallback(
async e => {
resetEntireStore();
},
[resetEntireStore],
);
}