Created
November 10, 2017 18:54
-
-
Save dex157/24468b5c644cfb341d83e6ca1695acd9 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
| import React, {Component, PureComponent} from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| import './index.css'; | |
| class App extends Component { | |
| state = { | |
| data: [1, 2, 3] | |
| }; | |
| handleClick = () => { | |
| const {data} = this.state; | |
| data.push(this.state.data.length + 1); | |
| this.setState({ | |
| data: data | |
| }); | |
| }; | |
| render() { | |
| const {data} = this.state; | |
| return ( | |
| <div> | |
| <button onClick={this.handleClick}>Update!</button> | |
| <Updater data={data} /> | |
| </div> | |
| ); | |
| } | |
| } | |
| class Updater extends Component { | |
| render() { | |
| const {data} = this.props; | |
| return ( | |
| <div> | |
| {data.map(element => ( | |
| <p key={element}>{element}</p> | |
| ))} | |
| </div> | |
| ); | |
| } | |
| } | |
| ReactDOM.render(<App />, document.getElementById('root')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment