Created
April 25, 2019 04:22
-
-
Save portothree/0e155a653022f460cd454f286e5dd90c 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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
class MyButton extends React.Component { | |
render() { | |
return <button | |
onClick={() => { this.props.handleClick(this.props.label); }}>{this.props.label}</button> | |
} | |
} | |
class MyLabel extends React.Component { | |
render() { | |
return <div>Botão clicado:{this.props.text}</div> | |
} | |
} | |
class App extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
labelText: '', | |
}; | |
} | |
setLabelText = (labelText) => { | |
this.setState({ labelText }); | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<MyLabel text={this.state.labelText} /> | |
<MyButton handleClick={this.setLabelText} label="Botao 1" /> | |
<MyButton handleClick={this.setLabelText} label="Botao 2" /> | |
<MyButton handleClick={this.setLabelText} label="Botao 3" /> | |
<MyButton handleClick={this.setLabelText} label="Botao 4" /> | |
</div> | |
); | |
} | |
} | |
ReactDOM.render ( | |
<App />, | |
document.querySelector('#root') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment