forked from LangGraph-GUI/LangGraph-GUI-reactflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphManager.js
32 lines (27 loc) · 792 Bytes
/
GraphManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// GraphManager.js
import React, { createContext, useContext, useState } from 'react';
import { useNodesState, useEdgesState} from 'reactflow';
const GraphManagerContext = createContext(null);
export const useGraphManager = () => {
return useContext(GraphManagerContext);
};
export const GraphManagerProvider = ({ children }) => {
const [nodes, setNodes, onNodesChange] = useNodesState([]);
const [nodeIdCounter, setNodeIdCounter] = useState(1);
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
const value = {
nodes,
setNodes,
onNodesChange,
edges,
setEdges,
onEdgesChange,
nodeIdCounter,
setNodeIdCounter,
};
return (
<GraphManagerContext.Provider value={value}>
{children}
</GraphManagerContext.Provider>
);
};