When a node rerenders due to new context api update, its siblings rerender
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What is the current behavior?
Nodes that use new context api force siblings nodes to rerender
What is the expected behavior?
Siblings should not rererender when a node updates due to context updates
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
16.3.1
Background:
i use react-navigation
with react-native. react-navigation uses the new context-api. withNavigationFocus
-HOC wraps the component with a NavigationConsumer
, a context consumer.
In this example i get unexpected rerenders:
const SomethingThatHasNavigation = withNavigationFocus(
class extends React.Component {
render() {
// i should rerender whenever navigation changes. That's fine. Its value is from context
return null
}
},
)
const ShouldNotRerender = class extends React.Component {
render() {
console.log('i should not rerender when my sibiling updates')
return null
}
}
const Test = class extends React.PureComponent {
render() {
console.log('test renders once')
return (
<View>
<SomethingThatHasNavigation />
<ShouldNotRerender />
</View>
)
}
}
What’s wrong? is this by design?
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
When does React re-render components? - Felix Gerschau
When the VDOM gets updated, React compares it to to a previous snapshot of the VDOM and then only updates what has changed...
Read more >Rerendering of one sibling component due to data update in ...
Now I have another api call (update request) on button click in Index.tsx file. This update request changes data in the layout's sidebar ......
Read more >How did I re-render: Sharing State through React-Context
It is a common pattern to “lift the state” up the component tree to a “Least-Common Ancestor” React Component if a state is...
Read more >React Context: Why am I getting unnecessary re-renders?
Every time React detects a change to something inside its context, it triggers a re-render on all of the context subscribers so that...
Read more >React key attribute: best practices for performant lists
update items that existed “before” and continue to exist “after” (i.e. re-render them). It's much easier to understand when you play with code...
Read more >
Top Related Medium Post
No results found
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
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think the fix would be in 0.56.
I’m running 16.4.
I have two independent dom nodes, far off from each other and not children/parents of either - not even siblings in a parent.
Any update to one forces an update to another, leading me to believe this feature is a singleton for a global context. Please advise @gaearon