I was watching a Pluralsight course on React and the instructor stated that props should not be changed. I’m now reading an article (uberVU/react-guide) on props vs. state and it says
Both props and state changes trigger a render update.
Later in the article it says:
Props (short for properties) are a Component’s configuration, its options if you may. They are received from above and immutable.
So props can change but they should be immutable?
When should you use props and when should you use state?
If you have data that a React component needs, should it be passed through props or setup in the React component via getInitialState?
This is related to props and state. One component will often be the prop of a child component. Props are passed to the child within the render method of the parent as the second argument to React.createElement() or, if you\’re using JSX, the more familiar tag attributes. MyChild name=this.state.childsName />.\n\nThe parent\’s state value of childsName becomes the child’s this.props.name.’ From the point of view, the name prop is immutable. If it needs to be changed, then the parent should just change its internal state: This.setState( Childsname: \’New name\’ ); .\n\nA natural follow-on question is: \”What if the child needs to change its name prop\” (usually through child events and parent callbacks)\”The child may expose an event (e.g., onNameChild name=this.state.childsName onReact), and then subscribe to the event by passing a call back handler.\n\nThe child would pass its requested name as an argument to the event callback by calling, e.g., this.props.onNameChanged(\’New name\’), and the parent would update its state by name in handleName: function(newName) This.setState( childsName; newName ); and by the name of the child\’s parent, handler would use the same name to update the state. handlename: handle name(( new name) in the newname)).