Share Complex Logic across React Components with Custom Hooks

Share this video with your friends

Send Tweet

A lot of the time, when you define logic in a component, you will want to reuse it in a few different places within your application as separate instances.

In this lesson, we will break out the logic of our StopWatch Component and use two instances within our stopwatch and compare the difference between the two lapse instances.

You'll learn:

  • Create a function as a custom hook for your components
  • Create multiple instances of the logic within a component
  • Compare the values between the two instances.
Hrafnkell Pálsson
Hrafnkell Pálsson
~ 6 years ago

Is there a reason for why you don't keep the reducer function local to useStopwatch? Just personal preference?

Kent C. Dodds
Kent C. Dodds(instructor)
~ 6 years ago

Just personal preference.

Bharat Patil
Bharat Patil
~ 4 years ago

Thank you Kent for the wonderful lessons, however, when I click on the "View code for this lesson" button on some of the lessons, it shows

Not Found
We could not find the sandbox you're looking for.