Custom hook là JavaScript function bắt đầu bằng 'use' có thể gọi các hooks khác.
- Dùng để tái sử dụng stateful logic giữa components.
- Mỗi component sử dụng custom hook có state instance riêng biệt, không chia sẻ.
js
function useLocalStorage(key, initial) {
const [value, setValue] = useState(initial)
// ...sync với localStorage
return [value, setValue]
}