Hands-on practice for this lecture. Write the code, see it run, understand the pattern.
Exercise 1 of 1
Three questions on the modal layout component: event propagation, controlled vs uncontrolled state, and why content components do not need to know about their container.
Question 1
<ModalBackground onClick={() => setShow(false)}>
<ModalContent onClick={e => e.stopPropagation()}>
<button onClick={() => setShow(false)}>Close</button>
{children}
</ModalContent>
</ModalBackground>What happens if you remove e.stopPropagation() from ModalContent?
Question 2
const Modal = ({ children }) => {
const [show, setShow] = useState(false);
...
};The Modal component manages its own open/close state. What does this make it?
Question 3
<Modal>
<DetailedUserRow user={users[0]} />
</Modal>Does DetailedUserRow need to know it is inside a Modal?
0 / 3 answered