pmndrs / jotai

👻 Primitive and flexible state management for React
https://jotai.org
MIT License
18.25k stars 590 forks source link

[atomWithQuery] how to reset queryAtom when it throw error #1129

Closed liaoliao666 closed 2 years ago

liaoliao666 commented 2 years ago

I have a issue that how can i reset the queryAtom, when query throw a error. I try to using QueryErrorResetBoundary of react query to reset this query. but unfortunately it does not work.

liaoliao666 commented 2 years ago

If its possible to get the nearest context of QueryErrorResetBoundary in the get function of queryAtom and it will be solved. but its not react hook, so that i can not think of any way to fix it. Can anyone has some workaround to solve this problem

dai-shi commented 2 years ago

My initial question is if this is solvable with normal atoms without jotai/query. If we find a solution with normal atoms, then we will make/modify jotai/query to work in the same way. So, the goal is once we have atoms (either from jotai/query or not), we want to handle them consistently (especially for Suspense and ErrorBoundary).

Would anyone like to dig into it? How does useState work?

vasilenka commented 2 years ago

I try to using QueryErrorResetBoundary of react query to reset this query. but unfortunately it does not work.

@liaoliao666 did you added the queryClient that you initialize for the react-query provider as the second parameter on your atomWithQuery?