4 ms·
That’s a good point, that example does feel a bit contrived. Interestingly though it is actually “canon” to call setState within the render function (for certai
by patdx 4y ago
That’s a good point, that example does feel a bit contrived. Interestingly though it is actually “canon” to call setState within the render function (for certain rare situations). I didn’t actually know this until I read the React beta docs: https://beta.reactjs.org/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes https://beta.reactjs.org/learn/you-might-not-need-an-effect#...
- activitypea 4y agoThat's a not a call to setState within the render function though, that's a declaration of an effect that sets state. Reference != call.