feat(react): add basic ssr support
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { useContext, type FC, type PropsWithChildren } from 'react';
|
||||
import { useContext, type ReactNode } from 'react';
|
||||
|
||||
import StoreContext from '../../contexts/RFStoreContext';
|
||||
import ReactFlowProvider from '../../components/ReactFlowProvider';
|
||||
import type { Node, Edge } from '../../types';
|
||||
|
||||
const Wrapper: FC<PropsWithChildren<unknown>> = ({ children }) => {
|
||||
function Wrapper({ children, nodes, edges }: { children: ReactNode; nodes?: Node[]; edges?: Edge[] }) {
|
||||
const isWrapped = useContext(StoreContext);
|
||||
|
||||
if (isWrapped) {
|
||||
@@ -12,8 +13,12 @@ const Wrapper: FC<PropsWithChildren<unknown>> = ({ children }) => {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
return <ReactFlowProvider>{children}</ReactFlowProvider>;
|
||||
};
|
||||
return (
|
||||
<ReactFlowProvider nodes={nodes} edges={edges}>
|
||||
{children}
|
||||
</ReactFlowProvider>
|
||||
);
|
||||
}
|
||||
|
||||
Wrapper.displayName = 'ReactFlowWrapper';
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ const ReactFlow = forwardRef<ReactFlowRefType, ReactFlowProps>(
|
||||
data-testid="rf__wrapper"
|
||||
id={id}
|
||||
>
|
||||
<Wrapper>
|
||||
<Wrapper nodes={nodes} edges={edges}>
|
||||
<GraphView
|
||||
onInit={onInit}
|
||||
onNodeClick={onNodeClick}
|
||||
|
||||
Reference in New Issue
Block a user