Skip to content

Atom not sync data with react query data when using gcTime, staleTime.Β #83

@ducpt-bili

Description

@ducpt-bili

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions