I am new to React and try to load different components based on state variables. I want my handler to dynamically know which state variable I am updating. As of now, I am explicitly passing the state name as a string.
State Variables
state = {
showLogin: false,
showHome: false
}
Handler Method
handleShow = (element) => this.setState({ element: true });
Buttons
{
!this.props.isAuthenticated ? (
<Button
variant="outline-primary"
onClick={() => this.handleShow("showLogin")}
>
Login
</Button>
) : (
<>
<Button
variant="outline-primary"
onClick={() => this.handleShow("showHome")}
>
Home
</Button>
<Button variant="outline-primary" onClick={this.authorizeUserMethod}>
LogOut
</Button>
</>
);
}