React

by Fulvio Cezar Canducci Dias

HTML

<div id="app"></div>

React

class App extends React.Component {
  constructor(props) {
  	super(props);
    this.state = {
    	show: true
    };
    this.toggleButton = this.toggleButton.bind(this);
  }
  toggleButton(){  	
    let { show } = this.state;
    show = !show;    
  	this.setState({show});
  }
  render() {
  	const { show } = this.state;
    const labelShow = show ? 'hide': 'show';
    return (
    	<div>
        <div style={{height: '20px'}}>
          { show && (<label>Show</label>) }
        </div>
        <div style={{height: '20px'}}>
          <button onClick={this.toggleButton}>{labelShow}</button>
        </div>
      </div>
    )
  }
}

ReactDOM.render(<App />, document.querySelector("#app"))