setProps

setProps

void setProps(
  object nextProps,
  [function callback]
)

When you're integrating with an external JavaScript application you may want to signal a change to a React component rendered with ReactDOM.render().

Calling setProps() on a root-level component will change its properties and trigger a re-render. In addition, you can supply an optional callback function that is executed once setProps is completed and the component is re-rendered.

This method is deprecated and will be removed soon. This method is not available on ES6 class components that extend React.Component. Instead of calling setProps, try invoking ReactDOM.render() again with the new props. For additional notes, see our blog post about using the Top Level API

When possible, the declarative approach of calling ReactDOM.render() again on the same node is preferred instead. It tends to make updates easier to reason about. (There's no significant performance difference between the two approaches.)

This method can only be called on a root-level component. That is, it's only available on the component passed directly to ReactDOM.render() and none of its children. If you're inclined to use setProps() on a child component, instead take advantage of reactive updates and pass the new prop to the child component when it's created in render().

doc_React
2016-06-23 03:32:28
Comments
Leave a Comment

Please login to continue.