JavaScript How to replace one React Component with another OnClick? replace react component,react replace component on click,react replace

I have a "sign up" button. When it is clicked, I would like for it to render a new component, called "SignUp". I would like for the new component to replace the "sign up" button.

Currently, I am using setState so that when the button is clicked, a new component is rendered. However, the button is not being replaced, the "SignUp" component is just rendered beside the button. What may be a good approach for me to replace the button with the new component being rendered?

I have provided my code below:

  export default class SignUpSignIn extends Component {

  constructor() {
     super();

     this.state = {
       clicked: false
     };

     this.handleClick = this.handleClick.bind(this);
   }

  handleClick() {
    this.setState({
      clicked: true
    });
  }

  render () {

    return (
    <div id="SignUpSignInDiv">

      <Col md="12" sm="12" xs="12" className="text-center">

        <div onClick={this.handleClick}>

          {this.state.clicked ? <SignUp /> : null}

        <Button id="SignUpButton" color="primary"> Sign Up </Button>

        </div>

       </Col>

    </div>
  )

  }
}
Answer:1

Well, you're not rendering both components conditionally, only the SignUp. Instead of having null in your ternary, render the sign in button when state.clicked === false:

render () {
  return (
    <div id="SignUpSignInDiv">
      <Col md="12" sm="12" xs="12" className="text-center">
        {this.state.clicked ? (
          <SignUp />
        ) : (
          <Button id="SignUpButton" color="primary" onClick={this.handleClick}> Sign Up </Button>
        )}
       </Col>
    </div>
  )
}
Answer:2

I need to include checkboxes as options in dropdown menu in Angular.

I need to include checkboxes as options in dropdown menu in Angular.

Im trying to change between two colors when I click on the event listener using JavaScript. When I trigger the click event, it changes the color to black. When I click on it again, I want it to change ...

Im trying to change between two colors when I click on the event listener using JavaScript. When I trigger the click event, it changes the color to black. When I click on it again, I want it to change ...

  1. switch between different chrome windows mac
  2. switch between different windows mac
  3. switch between different python versions
  4. switch between different jdk versions in mac
  5. switch between different windows of the same application mac
  6. switch between different windows in selenium
  7. switch between different java versions windows
  8. switch between different jdk versions in windows
  9. switch between different sheets in excel
  10. switch between different jdk versions in linux
  11. switch between different windows
  12. switch between different java versions
  13. switch between different java versions mac
  14. switch between different jre versions in windows
  15. switch between different network settings
  16. switch between different excel files
  17. switch between different node versions
  18. switch between different workbooks in excel
  19. switch between different branches in git
  20. switch between different browsers

I realize that this is improper syntax, but why is JavaScript ignoring the first number and giving a response instead of breaking? let myArray = [1,2,3,4] myArray[0,1] // 2 myArray[1,3] // 4 myArray[...

I realize that this is improper syntax, but why is JavaScript ignoring the first number and giving a response instead of breaking? let myArray = [1,2,3,4] myArray[0,1] // 2 myArray[1,3] // 4 myArray[...

  1. passing values in java
  2. passing values in url
  3. passing values in python
  4. passing values in javascript function
  5. passing values in c
  6. passing values in url php
  7. passing values in query string c#
  8. passing values in php
  9. passing values in python functions
  10. passing values in javascript
  11. passing values in onclick of javascript
  12. passing values in hyperlink html
  13. passing values in intent
  14. passing values in react
  15. passing values in url javascript
  16. passing values in html
  17. passing values in vba
  18. passing values in postman
  19. passing values in ajax
  20. passing values in angular

I have the following code to listen to click events on div elements. HTML: <div id="container"> <div id="1" class="square"></div> <div id="2" class="square"></div&...

I have the following code to listen to click events on div elements. HTML: <div id="container"> <div id="1" class="square"></div> <div id="2" class="square"></div&...