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

[Question] deps 的用法 #3

Closed
fi3ework opened this issue Oct 3, 2019 · 5 comments
Closed

[Question] deps 的用法 #3

fi3ework opened this issue Oct 3, 2019 · 5 comments

Comments

@fi3ework
Copy link

fi3ework commented Oct 3, 2019

按照文档中所说:如何解决store频繁更新所导致的性能问题

第二个传递的回调似乎能起到类似 useMemo 的作用,写了一个 demo https://codesandbox.io/s/react-md3t9 ,改了 withArgs,当调用 setDummy 的时候,尽管已经显式依赖了 counter 但还是 console 了 re-render。
看了下源码,里面有 useContext,用了 useContext 的 hook 似乎是不能直接在 hook 里做选择性渲染的。(https://github.com/facebook/react/issues/15156#issuecomment-474590693)

@awmleer
Copy link
Owner

awmleer commented Oct 3, 2019

把 reto 的版本改到最新(^0.5.0)就可以了~

@fi3ework
Copy link
Author

fi3ework commented Oct 3, 2019

cool

@fi3ework fi3ework closed this as completed Oct 3, 2019
@awmleer
Copy link
Owner

awmleer commented Oct 3, 2019

至于context的问题,reto的确是用到了context来做store的传递和获取,但是context里面放的是store的 container ,可以类似理解为,context 的 value 是一个 ref 值,每次 store 更新的时候,container(或者说是 ref )的引用是不会变的,为了能支持选择性的重渲染,store 更新的通知实际上是自己手工实现的,而不是基于context。。

@awmleer
Copy link
Owner

awmleer commented Oct 3, 2019

非常抱歉忘了把demo的依赖版本更新,给题主造成了些不必要的困扰。。我这就去改下~

@fi3ework
Copy link
Author

fi3ework commented Oct 3, 2019

感觉是 unstated-next 的升级版,手动控制更新的思路很好,不舍弃 context 也保持了分形,我最近也打算造个类似的轮子,reto 的思路很棒

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