Write Custom Hooks to Share Logic Between React Function Components

Elijah Manor
InstructorElijah Manor

Share this video with your friends

Send Tweet

A common way to share code across Components has been Render Prop Components or Higher Order Components (HOC), but extracting code with Hooks is much more straightforward. You can take code from an existing Component and pull out the hook logic into its own function for reuse.

Naman Sancheti
Naman Sancheti
~ a year ago

With the 'useDocumentTitle' custom hook, the code to compute the incomplete Todos is run on every render, whereas without the custom hook, it was run only when there was a change in the 'todos' - isn't it thereby better to NOT use a custom hook in this case for 'perf' reasons ?