Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

React - toggle state

0 votes
3 views
added Mar 6 in React by LC Marshal Captain (20,510 points)
import React from 'react';  

class MainComponent extends React.Component {
  constructor() {
        super();
        this.state = {
            shown: true,
        };
  }	
  
  toggle() {
        this.setState({
            shown: !this.state.shown
        });
  }
  
  render() {
    const { data } = this.props;
    const shown = {
      display: this.state.shown ? "block" : "none"
    };
    
    const hidden = {
      display: this.state.shown ? "none" : "block"
    }
    return (
      <div className="main-component">
        <button onClick={this.toggle.bind(this)}>Show calculator</button>
        <div className="display-hidden" style={ hidden }><MortgageCalculatorComponent MortgageCalculatorData={data} /></div>
      </div>
    )
  }
}
export default MainComponent;

 

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...