I'm kind of new to React and I'm having difficulty in invoking components through onClick event of a button.
Given below is the code segment
function Dev({value}){
return(
<Card>
<CardImg top width="100%" src={value.src} alt="Card image cap" />
<CardBody>
<CardTitle className='text-card'>{value.title}</CardTitle>
<CardText className='text-text'>{value.text}</CardText>
<Button className='text-button' onClick={(value)=>{
return(
<div>
{value.id ? <Login /> : <Sign />}
</div>
)
}}>{value.button}<i class={value.icon} aria-hidden="true"></i></Button>
</CardBody>
</Card>
);
}
value.id is either true or false, but either way the onClick is not firing.
The components Login and Sign are actually components consisting of a Modal.
Some help is deeply appreciated.
onClickdoesn't work, if it did, where would it be rendered? Would it replace the button? The Component? Get added to the existing JSX somewhere? Basically, there is no logical way for returning JSX from theonClickto work (thankfully it doesn't). So setting a flag in state and conditionally rendering is the way to go.