Summary

Examine the closing remarks of this lesson. Keep it in mind when building your own hooks.

The purpose of building a custom hook and using it with a global Store was to show the true power of using custom hooks in your own applications. With hooks, it is possible to achieve a better code composition that is easier to understand, maintain, and refactor.

As discussed earlier, building a custom hook helps share stateful logic between components. A custom hook can use its own dedicated state or use a global Store.

In fact, you can use one of the following options when it comes to integration with the state in custom hooks:

  • Use a third-party provider like Redux or MobX.
  • Use the global state within React.
  • Use dedicated state within a custom hook and share it through a getter function or simply return the reference to the state variable.

In this case, you leveraged the available global Store to manage the Notify state.

Get hands-on with 1200+ tech skills courses.