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

精读《unstated 与 unstated-next 源码》 #218

Closed
ascoders opened this issue Nov 18, 2019 · 3 comments
Closed

精读《unstated 与 unstated-next 源码》 #218

ascoders opened this issue Nov 18, 2019 · 3 comments

Comments

@ascoders
Copy link
Owner

ascoders commented Nov 18, 2019

unstatedunstated-next 这两个库都是很有趣的极简状态管理库,同时对比这两个库也非常有趣,欢迎发表你的看法。


精读《unstated 与 unstated-next 源码》

@ruandao
Copy link

ruandao commented Jun 7, 2020

有个疑问,要怎么在 component 外面 修改 unstated-next 的状态,用 useEffect 然后 里面 去subscribe 某个东西吗?

@tanyplzu
Copy link

tanyplzu commented May 22, 2021

“但这样还是显示使用了 useContext 的 API,并且对 Provider 的封装没有形成固定模式,这就是 usestated-next 要解决的问题。”

老师,这句话怎么理解,相比useContext,到底他解决了什么问题?显示使用useContext,原生API,有什么问题,写起来也很简洁。

@ascoders
Copy link
Owner Author

@tanyplzu 主要是规范的问题,你不能保证大家在 Provider.value 传递的一定是 useCounter 的返回值,可能有人又包了一个对象之类的。经过封装后,大家就可以形成思维定势,通过 useContainer 拿到的一定是 Hooks 返回值,而不是其它什么东西,这个改变看似小,其实是固定了以 Hooks 为第一公民的心智,其实蛮重要的。

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

3 participants