I'm trying to get rid of React's warning "It looks like you wrote useEffect(async () => ...) or returned a Promise. Instead, write the async function inside your effect and call it immediately".
I've been referencing this article https://www.robinwieruch.de/react-hooks-fetch-data to attempt to get rid of it, but alas, am unable to.
My useEffect:
useEffect(() => api.getAllPokemon(setResponse),[])
And my api.getAllPokemon async function which I've defined in an imported file:
const api = {}
api.getAllPokemon = async (cb) => {
await fetch('http://localhost:8080/pokemon', {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})
.then(async (pokemon) => await pokemon.json())
.then((pokemon) => pokemon.rows.map(({ name }) => name))
.then(pokemon => cb(pokemon))
};
export default api;