Skip to content

Instantly share code, notes, and snippets.

@DiegoPinho
Created November 21, 2017 20:41
Show Gist options
  • Save DiegoPinho/9d32958089122afb8bdc0fc60700897e to your computer and use it in GitHub Desktop.
Save DiegoPinho/9d32958089122afb8bdc0fc60700897e to your computer and use it in GitHub Desktop.
class App extends React.Component {
constructor(props) {
super(props);
this.state = {showModal: false};
this.mostraModal = this.mostraModal.bind(this);
this.escondeModal = this.escondeModal.bind(this);
}
mostraModal() {
this.setState({showModal: true});
}
escondeModal() {
this.setState({showModal: false});
}
render() {
const modal = this.state.showModal ? (
<Modal>
<div className="modal">
<div>Olá, eu sou um modal!</div>
<button onClick={this.escondeModal}>Hide modal</button>
</div>
</Modal>
) : null;
return (
<div>
<button onClick={this.mostraModal}>Show modal</button>
{modal}
</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