Skip to main content

useInvalidate

useInvalidate can be used to invalidate the state of a particular resource or dataProvider (with dataProviderName).

For example, creating a Posts with useCreate hook will invalidate the list (useList) and many (useMany) state of the Posts resource.

The hook is used internal in refine. Normally you don't need this hook, but we export it as it may be useful for some use-cases.

import { useInvalidate } from "@pankod/refine-core";

const invalidate = useInvalidate();

// To invalidate the list and many states of the Posts resource
invalidate({
resource: "posts",
invalidates: ["list", "many"]
});

// To invalidate the state of a Posts with an id of 1
invalidate({
resource: "posts",
invalidates: ["detail"],
id: 1,
});

// To invalidate the list and many states of the Posts resource of the dataProvider named "second-data-provider"
invalidate({
resource: "posts",
dataProviderName: "second-data-provider",
invalidates: ["list"],
});

// To invalidate all states of dataprovider named "second-data-provider"
invalidate({
dataProviderName: "second-data-provider",
invalidates: ["all"],
});

API Reference

Properties

PropertyDescriptionTypeDefault
invalidates
Required
The states you want to invalidate.all, resourceAll, list, many, detail, false
resourceResource name for State invalidation.string
idThe id to use when invalidating the "detail" state.BaseKey
dataProviderNameThe name of the data provider whose state you want to invalidate.stringdefault