diff --git a/.changeset/itchy-cups-wonder.md b/.changeset/itchy-cups-wonder.md new file mode 100644 index 0000000000..e8bf89880e --- /dev/null +++ b/.changeset/itchy-cups-wonder.md @@ -0,0 +1,5 @@ +--- +'@udecode/plate-dnd': patch +--- + +Fix: `useDndNode` calls a state setter during its render function diff --git a/packages/dnd/src/hooks/useDndNode.ts b/packages/dnd/src/hooks/useDndNode.ts index 5c7f084704..edea21453b 100644 --- a/packages/dnd/src/hooks/useDndNode.ts +++ b/packages/dnd/src/hooks/useDndNode.ts @@ -1,3 +1,4 @@ +import { useEffect } from 'react'; import { NativeTypes, getEmptyImage } from 'react-dnd-html5-backend'; import type { DropTargetMonitor } from 'react-dnd'; @@ -74,9 +75,12 @@ export const useDndNode = ({ } else { preview(drop(nodeRef)); } - if (!isOver && dropLine) { - setDropLine(''); - } + + useEffect(() => { + if (!isOver && dropLine) { + setDropLine(''); + } + }, [isOver, dropLine, setDropLine]); return { dragRef, diff --git a/yarn.lock b/yarn.lock index 5b4b21e840..44e6a8743a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6197,7 +6197,7 @@ __metadata: dependencies: "@udecode/plate-combobox": "npm:39.0.0" "@udecode/plate-markdown": "npm:39.2.0" - "@udecode/plate-selection": "npm:39.3.5" + "@udecode/plate-selection": "npm:39.3.7" ai: "npm:^3.4.10" lodash: "npm:^4.17.21" peerDependencies: @@ -7035,7 +7035,7 @@ __metadata: languageName: unknown linkType: soft -"@udecode/plate-selection@npm:39.3.5, @udecode/plate-selection@workspace:^, @udecode/plate-selection@workspace:packages/selection": +"@udecode/plate-selection@npm:39.3.7, @udecode/plate-selection@workspace:^, @udecode/plate-selection@workspace:packages/selection": version: 0.0.0-use.local resolution: "@udecode/plate-selection@workspace:packages/selection" dependencies: @@ -7245,7 +7245,7 @@ __metadata: "@udecode/plate-reset-node": "npm:39.0.0" "@udecode/plate-resizable": "npm:39.1.6" "@udecode/plate-select": "npm:39.0.0" - "@udecode/plate-selection": "npm:39.3.5" + "@udecode/plate-selection": "npm:39.3.7" "@udecode/plate-slash-command": "npm:39.0.0" "@udecode/plate-suggestion": "npm:39.0.0" "@udecode/plate-tabbable": "npm:39.0.0"