Quy ước đặt tên type theo format domain/eventName giúp dễ đọc trong DevTools.
Action creator là function trả về action object: const addItem = (item) => ({ type: 'cart/addItem', payload: item }) — giúp tránh typo và tái sử dụng.
Với Redux Toolkit, createSlice tự động tạo action creators và action types, không cần viết tay.
Lưu ý: đừng đặt non-serializable values vào action (Promise, class instance, function) vì sẽ phá vỡ DevTools time-travel và middleware như redux-persist.
EN
An action is a plain JavaScript object describing an event that occurred in the application.
It must have a type field (a string identifier) and typically includes a payload with data.
The convention of naming type as domain/eventName makes it easy to read in DevTools.
An action creator is a function that returns an action object: const addItem = (item) => ({ type: 'cart/addItem', payload: item }) — prevents typos and enables reuse.
With Redux Toolkit, createSlice automatically generates action creators and action types.
Pitfall: never put non-serializable values in actions (Promises, class instances, functions) as this breaks DevTools time-travel and middleware like redux-persist.
Xem toàn bộ State Management cùng filter theo level & chủ đề con.