Moving the functionality into a function, we get a custom hook: CodeSandBox: Custom hook (JS)
Generalize useFetch
: Add error
and re-invoke with setUrl
function:
-
Let's generalize the
useFetch
hook and allow new urls to be fetched with a function. -
Insight:
setUrl
is basically adoFetch
. -
Question: Why does hook not refetch?