I have an useEffect function that looks like this.
useEffect(() => {
getColls()
console.log(pageColl)
}, [])
The getColls() functions sets the pageColl variable.
//getColls()
const getColls = () => {
Service.getCollections()
.then(data =>
setPageColl(data.collections.find(coll => coll._id === userId))
)
}
//states
const [pageColl, setPageColl] = useState(null);
The pageColl should be set to an object but for some reason when I try to console.log(pageColl), I get returned a null. It is as if the setPageColl was never called. I know the data was returned in getColls as I can console.log it there.
.find(coll => coll._id === userId)
does not find a match? Double check the result before callingsetPageColl
to debug – CertainPerformance