Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to force refetch when using endpoint "initiate" function of redux-toolkit

I am using:

dispatch(api.endpoints.getPosts.initiate(undefined))

But Im receiving following error inside redux:

name:"ConditionError"
message:"Aborted due to condition callback returning false."

I found the meaning of this error at this question:

It means that an asyncThunk was not executed due to condition. If you are using RTK Query, that just means that another request was skipped because there was either already a request in flight or already a value in cache, so no request needs to be made. This is an internal rejection that RTK-Query uses to track component subscriptions and not an error.

But is there any way to force the refetch?

like image 888
Rashomon Avatar asked Nov 01 '25 10:11

Rashomon


1 Answers

Found the solution. You should use {forceRefetch: true} option:

dispatch(api.endpoints.getPosts.initiate(undefined, {forceRefetch: true}))
like image 163
Rashomon Avatar answered Nov 04 '25 01:11

Rashomon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!