Reputation: 21
const [modalShow, setModalShow] = React.useState(false);
return (
<>
<Button variant="primary" onClick={() => setModalShow(true)}> Launch vertically centered modal
<MyVerticallyCenteredModal
show={modalShow}
onHide={() => setModalShow(false)}
/>
</>
)
Upvotes: 1
Views: 252
Reputation: 991
If I understand correctly, you can pass a method to child component with props like this :
const TopComponent=()=>{
const [modalShow, setModalShow] = React.useState(false);
const MethodA=()=>{
setModalShow(false)
}
return (
<div>
<Button onClick={MethodA}/>
<MyVerticallyCenteredModal onClick={MethodA} />
</div>
);
};
const MyVerticallyCenteredModal = ({onClick}) => {
return (
<div>
<Button onClick={onClick}/>
</div>
);
};
Upvotes: 1