-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Hi,
Atom not sync data with react query data when using gcTime, staleTime. Below is my example:
export const todosQueryAtom = atomWithQuery(() => ({
queryKey: ["todos"],
queryFn: fetchTodos,
gcTime: 0,
staleTime: 0
}));
export const todosAtom = atom((get) => {
const todos = get(todosQueryAtom);
console.log("π ~ todosAtom ~ todos:", todos.isFetching)
if (!todos.isFetching) {
return todos.data?.map((todo) => atom(todo))
}
return []
});
// And in my component, i using this pattern in 2 my component.
const [dataQuery] = useAtom(todosQueryAtom)
console.log("π ~ dataQuery:", dataQuery.isFetching)
const [data] = useAtom(todosAtom)
....
But after some seconds, i click on my 2 screen, the dataQuery.isFetching is not change (not recall api in react-query) and i check data in todosAtom it still persist.
So i need to sync data by my self, right?
Thanks