inferno: `setState` in `componentWillReceiveProps` triggers `render`

Hi there. While working through a bunch of mini prototypes tonight I spotted a behavior I’m hoping you all can nick. This repro mocks a mini polling connector and consumer setup. The end-consumer updates its state in response to a prop change using the componentWillReceiveProps() lifecycle method. It appears that a setState call in componentWillReceiveProps triggers another render() pass vs coalescing with the existing props update.

I’m hoping that matching React’s component spec is possible. From component lifecycle specs:

Use this as an opportunity to react to a prop transition before render() is called by updating the state using this.setState(). The old props can be accessed via this.props. Calling this.setState() within this function will not trigger an additional render

Environment/runtime information is in #131. An example by way of picture:

console output while updating state in componentWillReceiveProps():

screen shot 2016-03-15 at 2 40 30 am

console output without state update:

screen shot 2016-03-15 at 2 42 01 am

Thanks again!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@mseeley I think I’ve located the route of this problem. I’ll push a fix for it to spike later tonight 😃 thanks for the help!