skip to Main Content

I have two api calls in promise ,so i have used promise.all and it is working fine.

Now i have one api call is enough to get the results but still i am using promise.all it is working fine.

I try to use promise instead of promise.all(here i used one api call )

my code here :

Promise.all([getCall()])
          .then(res => {
            if (res[0].errorObject) {
              props.Error(res[0]);
            } else { 
              <!----code here--->
            }
          })
          .catch(err => {
            console.log(err); 
          });

2

Answers


  1. getCall()
      .then(res => {
        if (res.errorObject) {
          props.Error(res);
        } else { 
          // <!----code here--->
        }
      })
      .catch(err => {
        console.log(err); 
      });
    
    Login or Signup to reply.
  2. You can using fetch()
    like this for example :

    useEffect(() => {
        fetch(url)
          .then((r) => r.json())
          .then((r) => {
            // save data from fetch request to state
            setData(r);
          });
      },[url]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search