Skip to content

Instantly share code, notes, and snippets.

@portothree
Created April 25, 2019 04:22
Show Gist options
  • Save portothree/0e155a653022f460cd454f286e5dd90c to your computer and use it in GitHub Desktop.
Save portothree/0e155a653022f460cd454f286e5dd90c to your computer and use it in GitHub Desktop.
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