useAtomCallback is a utility hook that creates imperative callbacks with access to atom getter and setter functions. It’s useful for reading or writing atoms outside of React’s render cycle.
When to use it
UseuseAtomCallback when you need to:
- Read or write atoms in event handlers without causing re-renders
- Perform imperative operations that need access to current atom values
- Create callbacks that read multiple atoms without subscribing to them
Signature
Parameters
callback: A function that receivesgetandsetfunctions plus any custom argumentsget: Function to read atom values (same as in atom read function)set: Function to write atom values (same as in atom write function)...args: Custom arguments passed when calling the callback
options: Optional configuration objectstore: Custom store to use (defaults to the store from Provider)
Returns
A stable callback function that can be called with the specified arguments.Basic Usage
Writing Atoms
With Custom Arguments
Reading Multiple Atoms
Async Callbacks
Comparison with Other Hooks
Debugging and Logging
Form Submission Example
TypeScript
useAtomCallback is fully typed: