My component code does something like this:
const [imageMap, setImageMap] = useState([]);
//...
useEffect(async () => {
const x = await getList();
setImageMap(x);
}, []);
console.log(imageMap);
The console.log
works fine and prints the list that returned from the function getList()
(which is a promise and takes a while to finish, since it retrieves data from the internet).
In the return statement of my component, I use imageMap.map(item => ...)
to exhibit all elements of imageMap
but it seems to be empty, since nothing appears. Am I doing something wrong?