Akila

Akila

  • NA
  • 216
  • 30.8k

To fix, cancel all subscriptions and asynchronous tasks in a useEffect

Feb 3 2022 6:23 AM

Hi,

I am using get method in useeffect.every time i open the page this error will appear

 

  useEffect(() => {

    async function fetchMyAPI() {

let isSubscribed = true

       axios

        .get(`${BASE_URL}${endpoint}`, {

          headers: {

            Authorization: `bearer ${accesstoken}`,

          },

        })

        .then(({data}) => {

if (isSubscribed) {

          setFilteredDataSource(data);

}

        });

    }

    fetchMyAPI()

return () => isSubscribed = false

  }, [])


Answers (1)