Open
Description
Description
When using atomWithQuery
with an atom created with atomWithQuery
(and loadable
) (*), it doesn't seem to work properly.
(*) using the atom in getVariables
and getPause
Reproduction
- Clone https://github.com/jet2jet/jotai-urql-test and
npm install
- Run
npm run start
- Open http://localhost:3000 , and click
Detailed
button - Click
Normal
button andDetailed
button for some times, and detailed list will stayloading
state
Others
I wonder the following block creates an atom inside the atom getter function.
https://github.com/jotaijs/jotai-urql/blob/v0.7.1/src/common.ts#L43-L64
If I modify the code like followings, it seems to work properly. (Is it OK to use atom generators inside the atom getter function?)
Modified code
const observableAtom = atom((get) => {
const args = getArgs(get)
const client = getClient(get)
const source = getPause(get) ? null : execute(client, args)
if (!source) {
return null
}
return pipe(source, toObservable)
})
// Note: if the function for `initialValue` accepts `get`, these atoms could be combined into one atom
const resultAtomWithSuspense = atomWithObservable<Result>(
(get) => get(observableAtom),
{}
)
const resultAtomWithoutSuspense = atomWithObservable<Result>(
(get) => get(observableAtom),
{ initialValue: urqlReactCompatibleInitialState }
)
const baseStatusAtom = atom((get) => {
if (!get(observableAtom)) return initialLoadAtom
// Enables or disables suspense based off global suspense atom
const resultAtom = get(suspenseAtom) ? resultAtomWithSuspense : resultAtomWithoutSuspense
if (process.env.NODE_ENV !== 'production') {
resultAtom.debugPrivate = true
}
return resultAtom
})
# FYI: jotai's atomWithObservable
also has calling an atom generator function inside the atom getter function:
https://github.com/pmndrs/jotai/blob/v2.4.3/src/vanilla/utils/atomWithObservable.ts#L137
Metadata
Metadata
Assignees
Labels
No labels