Answer the question
In order to leave comments, you need to log in
How to properly update a list in React Redux?
Hello, such a question:
I have a Store:
{
filters: {category: [1,2], tag: [3]},
list:[]
}
//Reducer
case FILTERS_CHANGED:
return state.merge({filters: state.filters.merge(action.payload)});
//Action
return dispatch => {
dispatch({type: constants.RESEARCH_FILTERS_CHANGED, payload: filter});
};
store.filters.subscribe(filters => {
//вызов action для подгрузки данных с бека и добавления их в лист
loadListAction(filters);
});
Answer the question
In order to leave comments, you need to log in
1) redux has a subscribe method .
2) Or look for a ready-made plugin. For example: redux-watch , redux-subscribe , redux-changes . Naturally, you can find many other similar plugins and choose which one you need.
I would do it through Redux Middleware.
Add middleware after.js
export default store => next => action => {
const {type} = action
const result = next(action)
switch (type) {
case constants.RESEARCH_FILTERS_CHANGED:
store.dispatch(loadListAction(store.getState( ).filters));
break;
}
return result
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question