UNPKG

reactflow-canvas-store

Version:

Global and multi-canvas state store for React Flow projects.

15 lines (14 loc) 453 B
import { useContext } from 'react'; import { GlobalStoreContext } from './GlobalStoreProvider'; //reactive store export function useGlobalStore(key) { const context = useContext(GlobalStoreContext); if (!context) { throw new Error('useGlobalStore must be used within a GlobalStoreProvider'); } const value = context[key]; const setValue = (val) => { context.setValue(key, val); }; return [value, setValue]; }