我将react-dnd 与react maui 树一起使用。我的目标是一次拖动多个项目。
\n我的方法是将树中所有选定的节点存储在 useState 中作为 ids(strings) 数组。单击节点时,状态会更新,我可以成功选择多个节点。
\n问题始于阻力。该项目未更新。
\n// returns the state\n// initially e.g. ["4372"] later it should return the correct result\nconst getState = () => {\n return selectedTreeNodes\n } \nRun Code Online (Sandbox Code Playgroud)\nconst [, drag] = useDrag(() => ({\n type: "el",\n item: getState(),\n end: (item, monitor) => {\n const dropResult = monitor.getDropResult<DropResult>();\n if (item && dropResult) {\n alert(`You dropped ${item} ${selectedTreeNodes} into ${dropResult}!`);\n }\n console.log("DROPPED", item, "SELECTEDFIELDS", getState()); // all these are only logging the …Run Code Online (Sandbox Code Playgroud)