-1

So here is my problem. Using async functions my response throws undefined but when i submit the second time throws the right response. here is my function:

 let showcode = async (data) => {

    try {
    setLoading(true);
    const url = `https://fortnite-api.com/v2/creatorcode?name=${data.code}`;
    let res = await axios.get(url);
    setInfo(res);
    console.log(info);
    setLoading(false);
  } catch (err) {
    setLoading(false);
    console("error aca "+ err);
  }
  };
  • 1
    Does this answer your question? [The useState set method is not reflecting a change immediately](https://stackoverflow.com/questions/54069253/the-usestate-set-method-is-not-reflecting-a-change-immediately) – Konrad Sep 25 '22 at 21:51

1 Answers1

0

Typically this happens when you try to use data that is not yet fully retrieved. You should await data first before trying to use it.

usamaster
  • 11
  • 3