Skip to main content
Version: 4.3

useResetter()

function useResetter(): () => void;

Mostly useful for imperatively resetting the cache.

Does not accept any arguments will always reset when called.

This is more than just expiring the items. Useful when so much has changed e.g. impersonating a user that the entire cache set must be thrown away and retrieved again.

Example

import { Resource } from 'rest-hooks';

// Server returns the logged in user
export default class CurrentUserResource extends Resource {
readonly id: string = null;
readonly name: string = '';
// ...
}
const USER_NUMBER_ONE: string = "1111";

function UserName() {
const user = useResource(CurrentUserResource.detailShape(), { });
const resetCache = useResetter();

const becomeAdmin = useCallback(() => {
// Changes the current user
impersonateUser(USER_NUMBER_ONE);
// Empty the cache
resetCache();
}, []);
return (
<div>
<h1>{user.name}<h1>
<button onClick={becomeAdmin}>Be Number One</button>
</div>
);
}