I am trying to dynamically display 3 buttons that each open a different modal. I'm struggling with finding the solution to open the modal that belongs to the button. I tried to implement it like the code below. It doesn't work which I expected but I"m struggling with finding the correct way of achieving the desired result.
button - modal code:
export default function SidenavButtons(props) {
const [modalShow, setModalShow] = React.useState(false);
return (
<React.Fragment>
<a class="dropdown-item" onClick={() => {setModalShow(true)}}>{props.usage}</a>
{
if(props.usage === "post" && modalShow){
<CreatePostModal
show={modalShow}
onHide={() => setModalShow(false)}
modelUsage={props.usage}
/>
}
if(props.usage === "tweet" && modalShow){
<CreateTweetModal
show={modalShow}
onHide={() => setModalShow(false)}
modelUsage={props.usage}
/>
}
if(props.usage === "tiktok" && modalShow){
<CreateTiktokModal
show={modalShow}
onHide={() => setModalShow(false)}
modelUsage={props.usage}
/>
}
}
</React.Fragment>
)
}