DEV Community

Discussion on: 💡 React Hooks: async function in the useEffect

 
rrsai profile image
Roy Ronalds

You mention two npm packages, but pulling in two extra npm packages just to get data from an api (something every page will require on average) is not a good "solution". And if those are the react external docs for using an api within useEffect, a lot of people are going to be googling elsewhere for solutions, as it's not even mentioned within the first ten pages of text. And explicitly says that APIs are one of the use cases of useEffect, then doesn't exaplain how to interact with an api in the guide itself.

At it's base, let's say you have fetch & React available, not two custom developed packages from the npm ecosystem. You then need to load in api data from the results of a promise, and using async/await should be the first step... ...which causes problems with useEffect.

Catch-22. What a mess.