-
-
Save tadjik1/f122a3459301ee6d4ad7359a01725e32 to your computer and use it in GitHub Desktop.
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
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