Provide more ways to bail out inside Hooks
See original GitHub issueThere’s a few separate issues but I wanted to file an issue to track them in general:
useState
doesn’t offer a way to bail out of rendering once an update is being processed. This gets a bit weird because we actually process updates during the rendering phase. So we’re already rendering. But we could offer a way to bail on children. Edit: we now do bail out on rendering children if the next state is identical.useContext
doesn’t let you subscribe to a part of the context value (or some memoized selector) without fully re-rendering. Edit: see https://github.com/facebook/react/issues/15156#issuecomment-474590693 for solutions to this.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:130
- Comments:140 (40 by maintainers)
Top Results From Across the Web
Hooks API Reference - React
If you update a State Hook to the same value as the current state, React will bail out without rendering the children or...
Read more >React useReducer Hook ultimate guide - LogRocket Blog
The dispatch method; Bailing out of a dispatch. Building a simple counter app with the useReducer Hook; useState vs. useReducer.
Read more >How Do React Hooks Actually Work? React.js Deep Dive #3
In this video, we will learn how React Hooks actually work. ... (in other words Why can't they be called inside loops or...
Read more >تويتر \ Michael Jackson على تويتر: "@sebmarkbage @mfpiccolo ...
Just read an article about React Hooks where the author claims that you ... Provide more ways to bail out inside Hooks ·...
Read more >State management with React Hooks and Reusable - Medium
It introduces a wrapper hell, no flexibility in dependency order, and can't use a selector and bail out of rendering.
Read more >
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
I would enjoy something like this to avoid unnecessary re-renders:
where the second parameter would work like the second parameter of
useEffect
, except it’s() => []
instead of[]
, withresult
being the response ofuseContext(MyContext)
.My personal summary is that new context is ready to be used for low frequency unlikely updates (like locale/theme). It’s also good to use it in the same way as old context was used. I.e. for static values and then propagate updates through subscriptions. It’s not ready to be used as a replacement for all Flux-like state propagation.