Skip to main content

useController()

Controller provides type-safe methods to manipulate the store.

For instance fetch, invalidate, and setResponse

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

function MyComponent({ id }) {
const ctrl = useController();

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

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

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

Examples

Todo App

Explore more Rest Hooks demos