Fix all typescript type issues

master
Jason Zhu 2023-05-29 21:04:46 +10:00
parent f06509e904
commit 8d70c86460
1 changed files with 13 additions and 5 deletions

View File

@ -5,14 +5,19 @@ import ReactFlow, {
applyEdgeChanges,
applyNodeChanges,
addEdge,
Node,
Edge,
NodeChange,
EdgeChange,
Connection,
} from 'reactflow';
// we have to import the React Flow styles for it to work
import 'reactflow/dist/style.css';
const initialEdges = [];
const initialEdges: Edge[] = [];
const initialNodes = [
const initialNodes: Node[] = [
{
id: '1',
data: { label: 'Hello' },
@ -31,16 +36,19 @@ const Flow = () => {
const [edges, setEdges] = useState(initialEdges);
const onNodesChange = useCallback(
changes => setNodes(nds => applyNodeChanges(changes, nds)),
(changes: NodeChange[]) =>
setNodes((nds: Node[]) => applyNodeChanges(changes, nds)),
[],
);
const onEdgesChange = useCallback(
changes => setEdges(eds => applyEdgeChanges(changes, eds)),
(changes: EdgeChange[]) =>
setEdges((eds: Edge[]) => applyEdgeChanges(changes, eds)),
[],
);
const onConnect = useCallback(
params => setEdges(eds => addEdge(params, eds)),
(params: Edge | Connection) =>
setEdges((eds: Edge[]) => addEdge(params, eds)),
[],
);