Framework decision: DÙNG Redux khi
- shared state cần ở nhiều component cách xa nhau — ví dụ user auth info cần ở Header, Sidebar, Feed và Modal đồng thời;
- state logic phức tạp với nhiều actions tương tác — shopping cart có coupon, discount, tax, shipping tính toán lẫn nhau;
- cần action history/audit trail — ứng dụng financial, collaborative editing cần biết ai làm gì lúc nào;
- team đã quen Redux với codebase lớn — migration cost cao hơn benefit. KHÔNG dùng Redux khi:
- chủ yếu là server state — dùng React Query thay, Redux cho server data là over-engineering;
- state chỉ local trong 1-2 component — useState là đủ;
- app nhỏ hoặc team mới — learning curve Redux + RTK không cần thiết
Alternatives landscape: Zustand cho global client state đơn giản (~8KB, zero boilerplate), Jotai cho atomic fine-grained state, React Query cho server state (thay thế 80% Redux use cases), Context API cho low-frequency updates như theme/locale.
Rule of thumb: nếu đang viết Redux chủ yếu để cache API data, hãy dùng React Query — Redux nên chỉ còn cho UI state thật sự global như auth, cart, notification preferences.
Framework decision — USE Redux when:
- shared state is needed across many distant components — e.g., user auth info required simultaneously in Header, Sidebar, Feed, and Modal;
- state logic is complex with many interacting actions — a shopping cart with coupons, discounts, taxes, and shipping that all affect each other;
- you need an action history/audit trail — financial or collaborative editing apps that need to know who did what and when;
- the team is already experienced with Redux in a large codebase — migration cost outweighs the benefit. DON'T use Redux when:
- it's mostly server state — use React Query instead; Redux for server data is over-engineering;
- state is only local to 1-2 components — useState is sufficient;
- the app is small or the team is new — the Redux + RTK learning curve is unnecessary
Alternatives: Zustand for simple global client state (~8KB, zero boilerplate), Jotai for atomic fine-grained state, React Query for server state (replaces 80% of Redux use cases), Context API for low-frequency updates like theme/locale.
Rule of thumb: if you're writing Redux primarily to cache API data, use React Query — Redux should be reserved for truly global UI state like auth, cart, and notification preferences.