Last active
November 7, 2018 11:15
-
-
Save luillyfe/6b87268363454892b8b3ec1c26e4c041 to your computer and use it in GitHub Desktop.
React: Props are immutable!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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