Skip to content

Instantly share code, notes, and snippets.

@tadjik1
Last active April 26, 2016 20:48
Show Gist options
  • Save tadjik1/f122a3459301ee6d4ad7359a01725e32 to your computer and use it in GitHub Desktop.
Save tadjik1/f122a3459301ee6d4ad7359a01725e32 to your computer and use it in GitHub Desktop.
class List extends Component {
constructor(props) {
super(props);
this.state = {
list: [1, 2, 3, 4, 5]
};
}
render() {
return (
<div>
<ul>
{this.state.list.map(num => {
return <li key={num}>{num}</li>
})}
</ul>
<button onClick={this.addElement.bind(this)}>add number</button>
</div>
);
}
addElement() {
this.setState({ // полный перерендер компонента
list: this.state.list.concat(this.state.list.length + 1)
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment