Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

强烈建议增加销毁方法 #81

Open
fgfg163 opened this issue Oct 8, 2021 · 0 comments
Open

强烈建议增加销毁方法 #81

fgfg163 opened this issue Oct 8, 2021 · 0 comments
Assignees

Comments

@fgfg163
Copy link

fgfg163 commented Oct 8, 2021

使用版本 1.1.4

hox使用 createModal 创建实例,但是没有销毁方法,在 modal 里使用副作用例如监听dom元素没有办法在最后销毁。

强烈建议增加一个销毁方法 destroy 以便手动触发 unmount

参考react-dom的销毁方法,

https://github.com/facebook/react/blob/784a725fe139b88c37f8b16d1d2225e88caf2612/packages/react-dom/src/client/ReactDOMLegacy.js#L361

https://github.com/facebook/react/blob/784a725fe139b88c37f8b16d1d2225e88caf2612/packages/react-dom/src/client/ReactDOMLegacy.js#L189

只需要在调用destroy方法时将 hox 内部的react root 清空,就可以卸载掉数据组件,触发unmount

// 第一个参数设置为null表示清空子组件
reconciler.updateContainer(null, container, null, null);
@awmleer awmleer self-assigned this Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants