0

I am sending an api call to cognito to get a jwtToken in return. I am using hooks for the API call but the issue is that I am getting infinite number tokens in return as the API call keeps getting data.

useEffect(() => {
    Axios.post(`${apiUrl}/api/auth/login`, loginInfo).then((res) =>
      setToken(res.data.accessToken.jwtToken)
    );
    Axios.get(getEventsUrl, config).then((response) =>
      setEventsData(response.data)
    );
  }, [loginInfo]);

How do I end only one request?

  • is `loginInfo` getting updated somehow? maybe its connected to a state. need more context – Adarsh Jan 21 '22 at 16:55
  • Seems like you created an infinite loop using `useEffect`. See this - https://stackoverflow.com/q/53070970/2873538 – Ajeet Shah Jan 21 '22 at 17:08

0 Answers0