My react project contains two components: one is parent and another is child. My parent component looks like this:
import React, {useState } from 'react';
import AddNewModal from './AddNewModal';
const MouseContainer = (props) =>{
const [show,setShow] = useState(false);
const toggle = () => setShow(!show);
return (
<div>
<button onClick={()=>setShow(!show)}>Toggle</button>
<p>{show && <AddNewModal show={props.show} setShow={props.setShow}/>}</p>
</div>
)
}export default MouseContainer;
And a child component that renders the modal like this:
import React, {useState} from 'react';
import { Modal, Button } from 'react-bootstrap';
import AddNewForm from './AddNewForm';
const AddNewModal = (show,setShow) => {
return(
<div>
<Modal show={show} setShow={setShow}>
<Modal.Header>
<Modal.Title>Modal heading</Modal.Title>
</Modal.Header>
<Modal.Body><AddNewForm/></Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={(props)=>props.setShow(!show)}>
Cancel
</Button>
</Modal.Footer>
</Modal>
</div>
)
}export default AddNewModal;
How can I update the stat so that the "cancel" button close the modal when clicked?