useSyncExternalStore (React 18) là hook chính thức để subscribe external stores (Redux, Zustand, browser APIs) đảm bảo consistent reads trong concurrent mode.
- Thay thế manual subscription trong useEffect.
- Nhận subscribe function và getSnapshot function.
- Libraries như Redux đã migrate sang hook này thay vì useEffect-based subscription.
useSyncExternalStore (React 18) is the official hook for subscribing to external stores (Redux, Zustand, browser APIs) while guaranteeing consistent reads in Concurrent Mode.
- It replaces manual subscription patterns inside useEffect.
- It takes a subscribe function and a getSnapshot function.
- Libraries like Redux have migrated to this hook instead of useEffect-based subscriptions.