You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Well, guys, I've read this post by @gaearon#2517 and still didn't figure out - does new context API is compatible with shouldComponentUpdate() since React v.16?
As far as I tested today shouldComponentUpdate is not callable at all while using this.context on the child component.
React version:
React & ReactDOM: v.16.13.1
Steps To Reproduce
Create a basic wrapper component with its child like: <MyContext.Provider value={store}>{child}</MyContext.Provider>
Set context on the child: static contextType = MyContext.
Try to call at least some console.log() inside ShouldComponentUpdate(), 100% the last one won't event being called.
The current behavior
Child component re-renders every time, shouldComponentUpdate even don't call at all.
The expected behavior
shouldComponentUpdate should be callable while used along with this.context on the child components.
UPD
I found shouldComponentUpdate working while using context on the child through <MyContext.Consumer> via HOC? That's the magic or a real bug...
The text was updated successfully, but these errors were encountered:
BiosBoy
changed the title
Bug: ShouldComponentUpdate doesn't being called when using this.context
Bug: shouldComponentUpdate doesn't being called when using this.context
Mar 30, 2020
BiosBoy
changed the title
Bug: shouldComponentUpdate doesn't being called when using this.context
Bug: shouldComponentUpdate() doesn't being called while using this.context
Mar 30, 2020
The propagation from Provider to its descendant consumers (including .contextType and useContext) is not subject to the shouldComponentUpdate method, so the consumer is updated even when an ancestor component skips an update.
I am having the same issue, I have react automatically rendering too much stuff when I update the context, where sometime only 1 consumer has changed. Is there any way to prevent propagation to consumers in some cases ?
update: answer is yes, see #15156
Well, guys, I've read this post by @gaearon #2517 and still didn't figure out - does new context API is compatible with
shouldComponentUpdate()
since React v.16?As far as I tested today
shouldComponentUpdate
is not callable at all while usingthis.context
on the child component.React version:
React & ReactDOM: v.16.13.1
Steps To Reproduce
<MyContext.Provider value={store}>{child}</MyContext.Provider>
static contextType = MyContext
.console.log()
insideShouldComponentUpdate()
, 100% the last one won't event being called.The current behavior
Child component re-renders every time,
shouldComponentUpdate
even don't call at all.The expected behavior
shouldComponentUpdate should be callable while used along with
this.context
on the child components.UPD
I found
shouldComponentUpdate
working while using context on the child through<MyContext.Consumer>
via HOC? That's the magic or a real bug...The text was updated successfully, but these errors were encountered: