Getting warning message ‘getDefaultMiddleware’ is deprecated

The middleware option in configureStore accepts a callback function, and that callback will be given getDefaultMiddleware as its argument: const store = configureStore({ reducer: rootReducer, middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(logger), }) Use that instead of the separately imported version.

correct usage of reduce-reducers

The difference is: combineReducers creates nested state reduceReducers creates flat state Consider following reducers. There are no action types to make things simpler: // this reducer adds a payload to state.sum // and tracks total number of operations function reducerAdd(state, payload) { if (!state) state = { sum: 0, totalOperations: 0 } if (!payload) return … Read more

How to update a value of a nested object in a reducer?

This is very common thing, and, actually, quite daunting. As far as I know, there is no really good and well-adopted solution in plain JS. Initially, Object.assign approach was used: return Object.assign({}, state, { categories: Object.assign({}, state.categories, { Professional: Object.assign({}, state.Professional, { active: true }) }) }); This is too straightforward and cumbersome, I admit … Read more

Access State inside of mapDispatchToProps method

You can use redux-thunk to create a separate action creator function which has access to getState, rather than defining the function inside mapDispatchToProps: function doTableActions(newValue, currentYear) { return (dispatch, getState) => { dispatch(updateAttributeSelection(‘genre’, newValue)); let state = getState(); // do some logic based on state, and then: dispatch(getTableData(newValue, currentYear)); } } let mapDispatchToProps = (dispatch, … Read more

Redux Saga async/await pattern

Yes, that’s the standard way to use Redux-Saga. You should never be calling the await function directly inside the saga-generator, because redux-saga is for orchestrating the side-effects. Therefore, any time that you want to run a side-effect you should do it by yielding the side-effect through a redux-saga effect (usually: call or fork). If you … Read more

tech