feat(react): ssr

This commit is contained in:
moklick
2023-10-05 17:28:05 +02:00
parent f37a2d9a19
commit 1acc59e44c
10 changed files with 90 additions and 22 deletions
@@ -6,11 +6,23 @@ import { Provider } from '../../contexts/RFStoreContext';
import { createRFStore } from '../../store';
import type { ReactFlowState, Node, Edge } from '../../types';
function ReactFlowProvider({ children, nodes, edges }: { children: ReactNode; nodes?: Node[]; edges?: Edge[] }) {
function ReactFlowProvider({
children,
nodes,
edges,
width,
height,
}: {
children: ReactNode;
nodes?: Node[];
edges?: Edge[];
width?: number;
height?: number;
}) {
const storeRef = useRef<UseBoundStoreWithEqualityFn<StoreApi<ReactFlowState>> | null>(null);
if (!storeRef.current) {
storeRef.current = createRFStore({ nodes, edges });
storeRef.current = createRFStore({ nodes, edges, width, height });
}
return <Provider value={storeRef.current}>{children}</Provider>;