UNPKG

zustand

Version:

🐻 Bear necessities for state management in React

14 lines (11 loc) 340 B
import ReactExports from 'react'; import { shallow } from 'zustand/vanilla/shallow'; const { useRef } = ReactExports; function useShallow(selector) { const prev = useRef(); return (state) => { const next = selector(state); return shallow(prev.current, next) ? prev.current : prev.current = next; }; } export { useShallow };