Skip to content

Instantly share code, notes, and snippets.

@Tin-Nguyen
Created April 13, 2017 21:29
Show Gist options
  • Save Tin-Nguyen/2421442042cd479f827a7c032a3b72ff to your computer and use it in GitHub Desktop.
Save Tin-Nguyen/2421442042cd479f827a7c032a3b72ff to your computer and use it in GitHub Desktop.
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