TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Simple way to share state using React Hooks and Context

131 点作者 hazdiego超过 6 年前

10 条评论

aogaili超过 6 年前
Well, that's nice. I guess the React community is aiming to try every permutation within potential state management solution space, I mean something have to work after all.
评论 #19103896 未加载
评论 #19104587 未加载
评论 #19104469 未加载
评论 #19104209 未加载
Jacqued超过 6 年前
Hey Diego!<p>Nice idea and examples! Let me know if I&#x27;m wrong, but the main difference between `createContainer` and a `React.createContext` call is that you memoize inputs, correct?<p>The way this interacts with Hooks to enable state sharing is pretty cool. Hopefully someone builds a complete i18n lib on top of something like this.
jsnelgro超过 6 年前
Also check out react-atom: <a href="https:&#x2F;&#x2F;github.com&#x2F;derrickbeining&#x2F;react-atom" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;derrickbeining&#x2F;react-atom</a><p>I stumbled across it earlier this week and it&#x27;s a joy to use so far. The api is inspired by clojure atoms, and typescript inference works great out of the box.
评论 #19108473 未加载
ng12超过 6 年前
Honestly I think I&#x27;m done with state management libraries. There&#x27;s no longer anything I can&#x27;t write cleanly with React.Context and hooks. The overhead of adding an dependency is no longer worth it.
评论 #19101792 未加载
评论 #19102084 未加载
评论 #19115205 未加载
评论 #19102907 未加载
评论 #19101871 未加载
rtpg超过 6 年前
Is there a way to use the React hook stuff without having to put the backend logic _inside_ of your UI generation code?<p>It really feels like if there was some way to put this really dirt-simple counter code into a plain-Jane Javascript object then a lot of this hand-wringing about state management in React goes away (contexts are an interesting little solution to things though)
评论 #19103155 未加载
评论 #19101991 未加载
评论 #19102333 未加载
评论 #19106919 未加载
评论 #19112134 未加载
thecatspaw超过 6 年前
I dont get hooks. How is this simpler than something like this?<p><a href="https:&#x2F;&#x2F;jsfiddle.net&#x2F;xv7y9eoz&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jsfiddle.net&#x2F;xv7y9eoz&#x2F;</a>
评论 #19104417 未加载
评论 #19104577 未加载
评论 #19104372 未加载
rbalicki超过 6 年前
Seems to solve a similar issue as <a href="https:&#x2F;&#x2F;github.com&#x2F;jamiebuilds&#x2F;unstated" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jamiebuilds&#x2F;unstated</a>
评论 #19100890 未加载
BilalBudhani超过 6 年前
I guess I&#x27;m still in a minority who likes Redux.
评论 #19104985 未加载
austincheney超过 6 年前
Maintaining state is an easily solved problem severely over engineered by frameworks. The central issue why this becomes so complicated is because developers who aren&#x27;t comfortable writing original code would rather deal with an ocean of configurations than a few architectural decisions.<p>That is problematic because configurations are settings not decisions, which means you need work arounds for edge cases and work arounds for the work arounds. If instead you treat everything as a requirement instead of anything as an edge case then you are forced to make decisions and write the corresponding code. New requirements may necessitate refactoring of current decisions down the road, but the code stays clean, small, and deliberate.<p>At the most simple you only need three things: a central consolidated point of settings (object), storage (localStorage), and interactions isolated to their respective purpose (handlers).
评论 #19104927 未加载
modarts超过 6 年前
How many times does the React community plan on skinning the same cat?
评论 #19103814 未加载
评论 #19104596 未加载