Trích xuất logic vào custom hook - function bắt đầu bằng 'use'. Custom hook có thể gọi useState, useEffect và các hooks khác. Component sử dụng custom hook sẽ có state riêng biệt, không chia sẻ instance.
Ví dụ: useWindowSize(), useDebounce(), useFetch() đều là custom hooks phổ biến.
Extract the logic into a custom hook — a function whose name starts with 'use'.
- The custom hook can call useState, useEffect, and other hooks.
- Each component that uses the hook gets its own isolated state instance; state is not shared.
- Common examples include useWindowSize(), useDebounce(), and useFetch().