FrontendDeveloper.in

React question detail

Can you combine **useReducer** with **useContext**?

Yes, it's common to combine useReducer with useContext to build a lightweight state management system similar to Redux:

const AppContext = React.createContext();

function AppProvider({ children }) {
const [state, dispatch] = useReducer(reducer, initialState);
return (
<AppContext.Provider value={{ state, dispatch }}>
{children}
</AppContext.Provider>
);
}
Back to all React questions
Get LinkedIn Premium at Rs 399