With query atoms, calling instance.invalidate() reevaluates the atom, thus recreating the promise. When migrating from a query atom to using injectPromise (a common task when more power is needed), instance.invalidate() is no longer sufficient to make the promise rerun.
There are many workarounds, but all are pretty inconvenient. This PR adds a runOnInvalidate config option to injectPromise itself to get the query atom behavior back.
const myPromiseAtom = atom(
'myPromise',
() => injectPromise(myPromiseFactory, [], { runOnInvalidate })
)
const myPromiseInstance = myEcosystem.getInstance(myPromiseAtom)
// now this will cause `myPromiseFactory` to rerun, updating the store's loading status:
myPromiseInstance.invalidate()
Description
With query atoms, calling
instance.invalidate()
reevaluates the atom, thus recreating the promise. When migrating from a query atom to usinginjectPromise
(a common task when more power is needed),instance.invalidate()
is no longer sufficient to make the promise rerun.There are many workarounds, but all are pretty inconvenient. This PR adds a
runOnInvalidate
config option toinjectPromise
itself to get the query atom behavior back.