Created
April 13, 2017 21:29
-
-
Save Tin-Nguyen/2421442042cd479f827a7c032a3b72ff to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class ListOfWords extends React.PureComponent { | |
render() { | |
return <div>{this.props.words.join(',')}</div>; | |
} | |
} | |
class WordAdder extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
words: ['marklar'] | |
}; | |
this.handleClick = this.handleClick.bind(this); | |
} | |
handleClick() { | |
// This section is bad style and causes a bug | |
const words = this.state.words; | |
words.push('marklar'); | |
this.setState({words: words}); | |
} | |
render() { | |
return ( | |
<div> | |
<button onClick={this.handleClick} /> | |
<ListOfWords words={this.state.words} /> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment