Skip to content

Latest commit

 

History

History
15 lines (9 loc) · 589 Bytes

custom-hook.md

File metadata and controls

15 lines (9 loc) · 589 Bytes

Custom hook

Split UI from business logic

Moving the functionality into a function, we get a custom hook: CodeSandBox: Custom hook (JS)

Generalize custom hook

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.

  • CodeSandBox: Result (JS)

  • Insight: setUrl is basically a doFetch.

  • Question: Why does hook not refetch?