3lang3 / react-vant

React mobile UI Components base on Vant
https://react-vant.3lang.dev
MIT License
1.32k stars 189 forks source link

fix: dialog.show method return close function #740

Closed itaober closed 1 month ago

itaober commented 1 month ago

问题

Dialog.show 方法调用返回的 destory 方法固定为 noop,不能按照预期行为工作: image

原因

调用 Dialog.show 时,return 的执行会优先于 TempDialog 组件中方法的执行。原 destory 为基础类型,无法在调用时获取到最新的期望内容。

修复方式

Map 存储 id-close 方法键值对,因为 Map 是引用类型,故在使用方调用时,能根据 id 拿到最新且对应的销毁方法。 其中 id 为 rv-dialog-root--${Date.now()},实际业务中可保证基本唯一。

具体代码见 PR。

github-actions[bot] commented 1 month ago

PR preview has been successfully built and deployed to https://react-vant-pr-740.surge.sh.