Open garrettmac opened 7 years ago
@garrettmac Right, the things that you mention above stand true for cases when a child component manages its state internally via setState()
calls. However, another use case is when a child update is triggered by a parent passing new props to it (such as in Flux/Redux flows), and in this case, making shouldComponentUpdate()
return false
stops the propagation of props from parents to children, and thus the child components are never re-rendered.
We need to do this, because once at.js
makes some modifications to the React-generated DOM we need these changes to be persisted (and not overwritten by a subsequent re-render when some child component updates), and the most straightforward way to do it is by disabling re-rendering of the children that the Target component wraps..
@XDex is there anyway work around I can do to to have a stateful component be a default component outside of the <Target>
wrapper?
@garrettmac Sorry, I'm not following, could you please provide some more context and clarify what you mean by default and fallback components?
@XDex if there are no offers to load or getOffer
or applyOffer
returns an error I don't want to loose my ability to manage state
.
Correct me if Im misunderstanding something but this plugin shouldn't be worried about
shouldComponentUpdate()
returningfalse
in line 37 of the component for it's children. This just prevents it's child nodes line 15 of the component from rerender and has no bearing on the Parent<Target>
node itself right?Take the following:
According to the react docs React will replace the first node that it detects change.
Further:
So if the component is maintained across renders is there anything i'm missing as to why you're setting
shouldComponentUpdate()
like that?(I also made this example pen to illustrate what
shouldComponentUpdate()
is doing if it helps)