Skip to main content

Moving state down

const [isOpen, setIsOpen] = useState(false);

return (
<Something>
{isOpen && <ModalDialog />}
<Button onClick={() => setIsOpen(true)}>Open dialog</Button>
<VerySlowComponent />
<BunchOfSlowStuff />
</Something>
);

Bad example! move state down.