Shouldn't the load function be in a useCallback hook? When you call it from a useEffect hook, you must add the load function into the dependency array. If you add it, that causes an infinite loop as the load function gets recreated on every render.
useCallback
useEffect
load
const load = useCallback(async () => { init(); setLoading(true); try { const result = await axios.fetch(url, {timeout: timeout}).data; setData(result); } catch (e) { setError(true); } setLoading(false); }, [url])
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Shouldn't the load function be in a
useCallback
hook? When you call it from auseEffect
hook, you must add the load function into the dependency array. If you add it, that causes an infinite loop as theload
function gets recreated on every render.