How would I go about creating a component using useEffect?
useEffect(() => {
fetch('https://website')
.then((res) => res.json())
.then((data) => {
setData(data)
// Use fetched data to create object "roles"
let cards = roles.map((path) => (
<Box m="sm" pt="xl">
<Card key={path.id} p="lg" radius="md href="#"
onClick={ () => handlePopup(path.role) }>
</Card>
</Box>
));
})
}
return (
<>
{cards} // this doesn't work.
</>
)
Current code is not working. "cards" is not loading, just getting a blank area. I'm keeping it all in the fetch because the data is dependent and I"m not sure how to split it up. Not sure if there's a smarter way.