fix: Add useUpdateNodeInternals hook to handle node class changes (#4058)
* fix: Add useUpdateNodeInternals hook to handle node class changes * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Cristhian Zanforlin Lousa <cristhian.lousa@gmail.com>
This commit is contained in:
parent
3e3d38a874
commit
dce5523f5e
1 changed files with 4 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import useFlowStore from "@/stores/flowStore";
|
import useFlowStore from "@/stores/flowStore";
|
||||||
import { NodeType } from "@/types/flow";
|
import { NodeType } from "@/types/flow";
|
||||||
import { cloneDeep } from "lodash";
|
import { cloneDeep } from "lodash";
|
||||||
|
import { useUpdateNodeInternals } from "reactflow";
|
||||||
|
|
||||||
const useHandleNodeClass = (
|
const useHandleNodeClass = (
|
||||||
nodeId: string,
|
nodeId: string,
|
||||||
|
|
@ -10,6 +11,7 @@ const useHandleNodeClass = (
|
||||||
) => void,
|
) => void,
|
||||||
) => {
|
) => {
|
||||||
const setNode = setMyNode ?? useFlowStore((state) => state.setNode);
|
const setNode = setMyNode ?? useFlowStore((state) => state.setNode);
|
||||||
|
const updateNodeInternals = useUpdateNodeInternals();
|
||||||
|
|
||||||
const handleNodeClass = (newNodeClass, type?: string) => {
|
const handleNodeClass = (newNodeClass, type?: string) => {
|
||||||
setNode(nodeId, (oldNode) => {
|
setNode(nodeId, (oldNode) => {
|
||||||
|
|
@ -23,6 +25,8 @@ const useHandleNodeClass = (
|
||||||
newNode.data.type = type;
|
newNode.data.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateNodeInternals(nodeId);
|
||||||
|
|
||||||
return newNode;
|
return newNode;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue