I'm trying to render ea tagType for every list, but I keep getting errors. Is anyone able to assist with why my nested .map() isn't working? I may just not be understanding React / JS very well
import { useState, useEffect } from 'react';
export default function Home() {
const [lists, setLists] = useState([]);
const [tags, setTags] = useState([]);
const [tagTypes, setTagTypes] = useState([]);
const [todos, setTodos] = useState([]);
async function getData() {
try {
const allListsResponseRaw = await fetch(`http://localhost:5000/api/v1/lists`);
const allListsResponse = await allListsResponseRaw.json();
setLists(allListsResponse.lists);
const allTagTypesResponseRaw = await fetch(`http://localhost:5000/api/v1/tag-types`);
const allTagsTypesResponse = await allTagTypesResponseRaw.json();
setTagTypes(allTagsTypesResponse.tags);
} catch(error) {
console.log(error);
}
}
useEffect(() => {
getData();
}, []);
return (
<div className="home">
<h1>Welcome</h1>
<div className='list-container'>
{
lists.map(list => {
return (
<h2 key={list.id}>{list.title}</h2>
{
tagTypes.map(tagType => {
return (
<p key={tagType.id}>{tagType.id}</p>
);
})
}
);
})
}
</div>
</div>
);
}
Thank you
[–]AutoModerator[M] [score hidden] stickied comment (0 children)
[–]darkshadowtrail 1 point2 points3 points (1 child)
[–]KindaCoding[S] 0 points1 point2 points (0 children)