1

I want to go DetailAboutUs page by clicking AboutUs button. How can I do it?

This is my code.

render(){
    var buttonStyle;
    return(
        <div>

           <button
               className="btn btn-default"
            style={buttonStyle}
               onClick={this.props.clickHandler(DetailAboutUs)}>About Us

           </button>

        </div>
    )
Shivam Kumar
  • 1,892
  • 2
  • 21
  • 33
NNNN
  • 19
  • 6

1 Answers1

0

You can have flag in the components state which tracks the click event, something like isButtonClicked = false.

Say you would like to load a page by name DetailAboutUs which is a component.

The code would look something like this.

isButtonClickedHandler = () => {
   this.setState({isButtonClicked = true});
}

render(){
    var buttonStyle;
    var detailAboutUs = this.state.isButtonClicked == true ? <DetailAboutUs> 
                        </DetailAboutUs> : null;

    return(
        <div>

           <button
               className="btn btn-default"
                style={buttonStyle}
                 onClick={this.isButtonClickedHandler()}>About Us

           </button>
          {detailAboutUs} //This will load only after the button click//

        </div>
    )
Praveen Rao Chavan.G
  • 2,772
  • 3
  • 22
  • 33