@zedux/atoms
Version:
A Molecular State Engine for React
16 lines (15 loc) • 520 B
JavaScript
import { injectAtomGetters } from './injectAtomGetters.js';
import { injectMemo } from './injectMemo.js';
/**
* Memoizes a callback function and wraps it in an `ecosystem.batch()` call.
*
* To memoize a callback without automatic batching, use `injectMemo` instead:
*
* ```ts
* injectMemo(() => myCallback, [])
* ```
*/
export const injectCallback = (callback, deps) => {
const { ecosystem } = injectAtomGetters();
return injectMemo(() => (...args) => ecosystem.batch(() => callback(...args)), deps);
};