Member-only story
4 Typical Scenarios for Custom React Hooks
Why do we need to build our own hooks?
- Custom Hooks can help us write more reusable code.
- Custom Hooks can help us split complex logic and simplify components.
What does this article for?
The official documentation is too brief in the chapter introducing custom hooks, and many important scenarios are not mentioned. So I would want to supplement the official documentation and summarize 4 typical scenarios for using custom Hooks.
Prerequisites
If you don’t know anything about React Hooks, please read the official documentation first to know why we should use hooks, and understand some build-in hooks such as useState
, useEffect
.
How to custom hooks?
First of all, we need to clarify a basic principle: React Hook is also a function. From the…