首页 > 解决方案 > React DnD:动态接受类型:删除类型时,将目标限制为该类型

问题描述

我希望有人可以帮助我。我在 useDrop 挂钩中定义了多种类型,如果删除了一种类型,我想将下一次删除限制为这种类型。第一次放置后,我知道过滤类型,但似乎 useDrop 没有接受接受类型的更改,仍然接受默认列表。

再生产

https://codesandbox.io/s/mystifying-shtern-guxdw?file=/src/Dustbin.jsx

重现行为的步骤:

  1. 转到代码沙箱
  2. 拖放BOX类型

预期行为您现在应该能够只删除 BOX 类型而不是 BOX2

https://github.com/react-dnd/react-dnd/issues/2862

标签: javascriptreactjsreact-dnd

解决方案


"a workaround would be to use a key property equal to your accepted types on the component which contains your drop target. This would ensure that it re-mounts once you change the acceptable type(s)"

https://github.com/react-dnd/react-dnd/issues/2732#issuecomment-677739822


推荐阅读