javascript - React DnD:动态接受类型:删除类型时,将目标限制为该类型
问题描述
我希望有人可以帮助我。我在 useDrop 挂钩中定义了多种类型,如果删除了一种类型,我想将下一次删除限制为这种类型。第一次放置后,我知道过滤类型,但似乎 useDrop 没有接受接受类型的更改,仍然接受默认列表。
再生产
https://codesandbox.io/s/mystifying-shtern-guxdw?file=/src/Dustbin.jsx
重现行为的步骤:
- 转到代码沙箱
- 拖放BOX类型
预期行为您现在应该能够只删除 BOX 类型而不是 BOX2
解决方案
"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
推荐阅读
- servlets - Java Web 应用程序:无法从 jsp 页面启动 MVC 控制器 (Servlet) 类
- javascript - 函数没有获取值?
- teradata-sql-assistant - Teradata SQL 将单个字符串拆分为表行
- regex - 无法匹配正则表达式中的多个数字
- batch-file - 使用 for 循环在一个范围内进行标记并排序
- macos - PySpark 在 Mac 上本地运行:原因:java.io.IOException:无法运行程序“/usr/local/Cellar/apache-spark/3.0.1/libexec/bin”
- html - 为什么我没有得到正确的输出?
- sql - Dremio 转换时间戳
- rapidjson - Rapid Json:随机问题和 pstack 正在生成
- swift - Assetwriter 时间倒退并在 gpu 图像中快速获得 nil 输出