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>
)
}
}
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>
)
}
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 ...
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[...
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&...