jotaijs / jotai-tanstack-query

Jotai integration library for TanStack Query
MIT License
210 stars 14 forks source link

atomWithSuspenseQuery execute the query even if `enabled` is false #74

Closed drodrigue-solace closed 6 months ago

drodrigue-solace commented 7 months ago

When using atomWithSuspenseQuery() with a false for the enabled option, the query is executed anyway. It should be executed only if the enabled option is true.

e.g.

const enabledAtom = atom(false);
const queryAtom = atomWithSuspenseQuery((get) => ({
    queryKey: ["my-key"],
    queryFn: () => fetch("the-url"),
    enabled: get(enabledAtom)
}));

I would have expected that the query stay pending until the enabledAtom is set to true in the example above.

Tested with:

kalijonn commented 6 months ago

v0.8.x only supports react query v5. we're setting enabled to true for all suspense queries to be consistent with react query v5.

drodrigue-solace commented 6 months ago

I can understand that if enabled is not specified, the code can set it to true, but it seems I still should be able to control that somehow. Obviously I don't know all the internal details and behaviours of react-query.

feledori commented 6 months ago

enabled can not be set with a suspense query. As with a suspense query the data must be there. It has to be available. Suspense forces you in a way to structure you app like that. The thing is here are the typings wrong as the enabled option should not be accessible in a suspense query.

drodrigue-solace commented 6 months ago

Closing issue