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:
anovazzi1 2024-10-07 18:04:07 -03:00 committed by GitHub
commit dce5523f5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
import useFlowStore from "@/stores/flowStore";
import { NodeType } from "@/types/flow";
import { cloneDeep } from "lodash";
import { useUpdateNodeInternals } from "reactflow";
const useHandleNodeClass = (
nodeId: string,
@ -10,6 +11,7 @@ const useHandleNodeClass = (
) => void,
) => {
const setNode = setMyNode ?? useFlowStore((state) => state.setNode);
const updateNodeInternals = useUpdateNodeInternals();
const handleNodeClass = (newNodeClass, type?: string) => {
setNode(nodeId, (oldNode) => {
@ -23,6 +25,8 @@ const useHandleNodeClass = (
newNode.data.type = type;
}
updateNodeInternals(nodeId);
return newNode;
});
};