useEffect(() => {
(async () => {
try {
let url = `https://graph.instagram.com/${id}/children?access_token=${process.env.ig_user_access_token}`;
const {
data: { data },
} = await axios.get(url);
let imagesUrl = data?.map(async item => {
const { data: singleImage } = await axios.get(
`https://graph.instagram.com/${item.id}?fields=media_url&access_token=${process.env.ig_user_access_token}`
);
return singleImage;
});
Promise.all(imagesUrl).then(res => {
setCarouselImages(res);
});
} catch (error) {
toast({
title: 'Error',
description: error.message,
status: 'error',
duration: 9000,
isClosable: true,
});
}
})();
}, []);