reactflow-canvas-store
Version:
Global and multi-canvas state store for React Flow projects.
16 lines (15 loc) • 562 B
JavaScript
import React, { createContext, useState } from 'react';
export const CanvasStoreContext = createContext(null);
export const CanvasStoreProvider = ({ children }) => {
const [store, setStore] = useState({});
const setCanvasValue = (canvasId, key, value) => {
setStore(prev => ({
...prev,
[canvasId]: {
...(prev[canvasId] || {}),
[key]: value,
},
}));
};
return (React.createElement(CanvasStoreContext.Provider, { value: { store, setCanvasValue } }, children));
};