injectInvalidate
This injector is deprecated and will be removed in the next major release. Use the following pattern instead:
const self = injectSelf()
// then in a callback or effect:
self.invalidate()
See injectSelf()
import { injectInvalidate } from '@zedux/react'
An unrestricted injector that returns an invalidate()
function. This invalidate()
function can be used to force a reevaluation of the current atom instance.
In general, try to avoid impure, mutation-oriented, or generally non-reactive patterns that might require manual invalidation. However, there are some use cases for it. Specifically when using Query Atoms, this injector may be a key piece of your state flow.
Examples
injectInvalidate
is the equivalent of the following pattern in React:
const [, forceRender] = useState()
...
forceRender({})
(Here's the above example in atom form):
const invalidate = injectInvalidate()
...
invalidate()
Signature
- Simplified
- TypeScript
injectInvalidate = () => invalidate
declare const injectInvalidate: () => () => void
A function that can be called to force a reevaluation of the current atom instance. Signature:
invalidate = () => void
Only use in callbacks or certain conditions of an effect.
// Don't do this! (would trigger an infinite evaluation loop):
const invalidate = injectInvalidate()
invalidate()