I was trying the useEffect
example something like below:
useEffect(async () => {
try {
const response = await fetch(`https://www.reddit.com/r/${subreddit}.json`);
const json = await response.json();
setPosts(json.data.children.map(it => it.data));
} catch (e) {
console.error(e);
}
}, []);
and I get this warning in my console. But the cleanup is optional for async calls I think. I am not sure why I get this warning. Linking sandbox for examples. https://codesandbox.io/s/24rj871r0p
Best Answer
I suggest to look at Dan Abramov (one of the React core maintainers) answer here:
You can read more about experimental suspense here.
If you want to use functions outside with eslint.
If you will use useCallback, look at example of how it works useCallback. Sandbox.