From 8a5d6776e4c8cecc7a429ff41422efba5c884dfe Mon Sep 17 00:00:00 2001 From: arnaud Date: Tue, 31 Oct 2023 16:39:09 +0100 Subject: [PATCH] fix(useMikadoGraph): display new nodes after adding a prerequisite --- app/mikado-graph/component/mikado-graph.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/mikado-graph/component/mikado-graph.tsx b/app/mikado-graph/component/mikado-graph.tsx index a31213b..6c5205e 100644 --- a/app/mikado-graph/component/mikado-graph.tsx +++ b/app/mikado-graph/component/mikado-graph.tsx @@ -1,6 +1,6 @@ 'use client'; -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { StatusView } from '@/api/mikado-graph/mikado-graph'; import AddPrerequisiteForm from '@/mikado-graph/component/add-prerequisite-form'; import { Translation } from '@/tools/i18n/intl-provider'; @@ -126,8 +126,13 @@ export default function Graph({ }: { mikadoGraph: MikadoGraph, }) { - const [nodes, , onNodesChange] = useNodesState(mikadoGraph.nodes); - const [edges, , onEdgesChange] = useEdgesState(mikadoGraph.edges); + const [nodes, setNodes, onNodesChange] = useNodesState(mikadoGraph.nodes); + const [edges, setEdges, onEdgesChange] = useEdgesState(mikadoGraph.edges); + + useEffect(() => { + setEdges(mikadoGraph.edges); + setNodes(mikadoGraph.nodes); + }, [mikadoGraph]); return (