feat(control): Introduce control hooks#108
Open
599316527 wants to merge 5 commits intoecomfe:masterfrom
Open
Conversation
Member
|
我终于看懂了……核心是利用 具体到类型的完备性和命名,我再仔细推敲一下 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
目标
通过hooks简化弹窗类组件的调用。
现状
实现弹窗交互时我们通常写出这样的代码。当组件需求越来越复杂,或者一个页面中出现多个弹窗时,这样的写法使得组件内 state 满天飞,可维护性急剧下降。同时,打开弹窗操作所引起的 state 更新会导致整个组件刷新,照成性能问题。
解决
把弹窗相关逻辑独立成组件提升可维护性。并且通过
useControl和useControlSourcehook 来关联两者,实现简单易用。这样无论是直接使用 open 还是把它通过 context 往下传递,调用它开关弹窗都不会导致其它地方的无意义刷新。
目前在业务代码里用起来还挺方便的,所以感觉可以放到 huse 里面。
更详细的例子可以看 demo 实现。