I have a MUI dialog component that triggers a useLazyQuery action on save to fetch data.
Then on success dispatches another action
My problem is, that after success, I want to reset the state of the useLazyQuery hook in the dialog component, because after success/fail the state is "stuck" like this in the component.
I am confused how should I approach this...
Dismount and mount the dialog component works but it removes the fadeout animation and also unsubscribe the query endpoint.
Is there a best practice here that I am missing?
https://redux-toolkit.js.org/rtk-query/api/created-api/hooks
Hmm, instead of a lazyQuery
I'd probably just use a normal query hook with a setState
. That way you can just skip
it.
const [arg, setArg] = useState(null)
const result = useMyQuery(arg, { skip: arg == null })
And then setArg(null)
to "reset" the thing.
So I ended up using RTKQuery without hooks
created a Custom hook and inside used initiate and select
with useSelector and dispatch,
than I can reset someId when isSuccess is true
dispatch(api.endpoints.getData.initiate(someId));
const {data, isError, isLoading} = useSelector(state => api.endpoints.getData.select(someId)(state))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.