TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

131 pointsby hazdiegoover 6 years ago

10 comments

aogailiover 6 years ago
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 未加载
Jacquedover 6 years ago
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.
jsnelgroover 6 years ago
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 未加载
ng12over 6 years ago
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 未加载
rtpgover 6 years ago
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 未加载
thecatspawover 6 years ago
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 未加载
rbalickiover 6 years ago
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 未加载
BilalBudhaniover 6 years ago
I guess I&#x27;m still in a minority who likes Redux.
评论 #19104985 未加载
austincheneyover 6 years ago
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 未加载
modartsover 6 years ago
How many times does the React community plan on skinning the same cat?
评论 #19103814 未加载
评论 #19104596 未加载