Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

promise.all inside useEffect

  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,
        });
      }
    })();
  }, []);
 
PREVIOUS NEXT
Tagged: #useEffect
ADD COMMENT
Topic
Name
4+3 =