feat(react): add basic ssr support

This commit is contained in:
moklick
2023-10-04 16:03:23 +02:00
parent 53c04e2546
commit 86c041c2a0
21 changed files with 2915 additions and 606 deletions
@@ -1,20 +1,20 @@
import { useRef, type FC, type PropsWithChildren } from 'react';
import { useRef, type ReactNode } from 'react';
import { type StoreApi } from 'zustand';
import { UseBoundStoreWithEqualityFn } from 'zustand/traditional';
import { Provider } from '../../contexts/RFStoreContext';
import { createRFStore } from '../../store';
import type { ReactFlowState } from '../../types';
import type { ReactFlowState, Node, Edge } from '../../types';
const ReactFlowProvider: FC<PropsWithChildren<unknown>> = ({ children }) => {
function ReactFlowProvider({ children, nodes, edges }: { children: ReactNode; nodes?: Node[]; edges?: Edge[] }) {
const storeRef = useRef<UseBoundStoreWithEqualityFn<StoreApi<ReactFlowState>> | null>(null);
if (!storeRef.current) {
storeRef.current = createRFStore();
storeRef.current = createRFStore({ nodes, edges });
}
return <Provider value={storeRef.current}>{children}</Provider>;
};
}
ReactFlowProvider.displayName = 'ReactFlowProvider';