DEV Community

Discussion on: Why React projects still use Redux

Collapse
 
pengeszikra profile image
Peter Vivo

After 3 years redux coding, I turn to usie only useReducer + props without Context, that is the most simple solution. If I faced with complex problem, then change useReducer with useSagaReducer, without use any global state.

// simple combine reducer
export const combineReducers = reducers => (state, action) => 
  Object.entries(reducers).reduce(
    ( prevState, [key, reducer]) => {
        const subState = reducer(prevState[key], action);
        return prevState[key] === subState 
          ? prevState 
          : {...prevState, [key]:subState}
        ;
      } 
    , state
  );

so i think good to know about redux, redux-saga and choose lightest state management for your app - depend complexity.

Collapse
 
alexandrudanpop profile image
Alexandru-Dan Pop

I had no idea of the useSagaReducer hook, pretty cool!