V
V
Vlad2019-10-09 16:03:53
redux
Vlad, 2019-10-09 16:03:53

How to combine several reducers into one?

There are two reducers, you need to get one. How to do it?

import * as constants from '../constants';

const initialState = [];

export function queryLog(state = initialState, action): object {
    if (action.type === constants.LOAD_QUERY_LOG_STOP) {
        action.queryLog.forEach(e => {
            if ('dt_changelog' in e) {
                e['dt_changelog'] = e.dt_changelog * 1000;
            }
        });
        return action.queryLog;
    }
    return state;
}

import * as constants from '../constants';

const initialState = [];

export function comments(state = initialState, action): object {
    if (action.type === constants.LOAD_COMMENTS_STOP || action.type === constants.SENT_COMMENT) {
        action.comments.forEach(e => {
            if ('datetime' in e) {
                e.datetime = e.datetime * 1000;
            }
        });
        return action.comments;
    }
    return state;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
harabudjasim, 2019-10-09
@supeeeee_r_man

https://redux.js.org/api/combinereducers#reducers-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question