const [dataDB, setDataDB] = useState(null);
const [dataContent, setDataContent] = useState(null);
...
useEffect(() => {
fetch('some-url.com')
.then((res) => res.json())
.then((dataDB) => {
setDataDB(dataDB)
console.log("dataDB: " + dataDB); // this works fine
})
.then((dataContent) => {
const role = tabs.find(x => x.id == dataDB[0][0]+1)
setDataContent(role);
console.log("dataContent: " + dataContent); // getting null here
})
}, [])
I can't get the second setState (setDataContent) to work. I tried putting the setDataDB and setDataContent together but still having the same issue. It has to be I'm not understanding promises.
Edit: Was reading https://nextjs.org/docs/basic-features/data-fetching/client-side I'm trying to update dataContent based on value of dataDB.