Skip to content

RTK Query: Refetch when global state changes #3304

Answered by markerikson
Raadski asked this question in Q&A
Discussion options

You must be logged in to vote

The usual suggested pattern is to do this at the component level with the hooks:

const someValue = useSelector(selectSomeValue);
const { data } = useSomeQuery(someValue);

That way the query hook will re-run and fetch a new result every time someValue changes.

If you're doing that in many components, you could extract those lines into a custom hook and use that.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@phryneas
Comment options

@Raadski
Comment options

@saksham-tiwari
Comment options

Answer selected by Raadski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants