Skip to content

render as a function of props and state #1387

@chenglou

Description

@chenglou

This comes from my discussion with several people around animation, but I feel like it's important enough to warrant its own issue.

We already insist that render should be a pure function of this.props and this.state. How about taking this further and pass those in CompositeComponent? This way we can write:

render: function(props, state) {
  return <div>{props.something}</div>;
}

While most of the time we'll still call render(this.props, this.state) internally, with this we will be able to do render(somePrevProps, someTestState) from React or even from the user. Being able to "test the water" would be very valuable in the future. For example:

componentWillReceiveProps: function(nextProps) {
  var result1 = this.render(this.props, this.state);
  var result2 = this.render(nextProps, this.state);
  // Collection of changed stuff. Good for preparing mounting/unmounting animations or such logic.
  React.reconciler.getDiff(result1, result2);
  this.setState({...});
}

I've heard this can also solve some problems with pendingState? Not too familiar with the issue.
@jordwalke @sebmarkbage @petehunt

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions