Skip to content

Instantly share code, notes, and snippets.

@luillyfe
Last active November 7, 2018 11:15
Show Gist options
  • Save luillyfe/6b87268363454892b8b3ec1c26e4c041 to your computer and use it in GitHub Desktop.
Save luillyfe/6b87268363454892b8b3ec1c26e4c041 to your computer and use it in GitHub Desktop.
React: Props are immutable!
const News = props => {
const changeTitle = () => {
// Since props are read-only, you are not allowed to do so
props.changeTitle("Title changed!");
};
return (
<div>
<h1>{props.title}</h1>
<div>{props.content}</div>
<button onClick={changeTitle}>Mutate!</button>
</div>
);
};
class App extends Component {
...
<News title={title} content={content} changeTitle={this.changeTitle} />
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment