Mini Redux dùng Context + useReducer: store dùng chung cho toàn app mà không cần thư viện ngoài.
jsx
const StoreContext = createContext();
function StoreProvider({ children }) {
const [state, dispatch] = useReducer(reducer, initialState);
return (
<StoreContext.Provider value={{ state, dispatch }}>
{children}
</StoreContext.Provider>
);
}
const useStore = () => useContext(StoreContext);Phỏng vấn thường hỏi để test hiểu state management internals.
Create a context + reducer: const StoreContext = createContext(); function StoreProvider({ children }) { const [state, dispatch] = useReducer(reducer, initialState); return <StoreContext.Provider value={{ state, dispatch }}>{children}</StoreContext.Provider>; } Add const useStore = () => useContext(StoreContext).
Interviewers ask this to test understanding of state management internals.