I made a modal window in React. I created a state called modalbool and made the modal window appear when modalbool is true. And I created a parent component called Backdrop and closed the modal window when I clicked the Background. However, even if I click the ModalContainer component, which is a child component, modalClosefunc is executed and the modal window is closed. How can I make modalbool become false and close the modal window when only the Backdrop component is pressed?
this is my code
const Backdrop = styled.div`
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top:0;
left: 0;
background-color: rgba(0,0,0,0.7);
width: 100vw;
height: 100vh;
`
const ModalContainer = styled.div`
position: relative;
width: 700px;
height: 600px;
background-color: lightcoral;
`;
const [modalbool, setModalbool] = useState(false);
{modalbool ? (
<Backdrop onClick={modalClosefunc}>
<ModalContainer>
</ModalContainer>
</Backdrop>
) : null