Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

283
Vistas
How should the actions and reducer structure be so that the data from 2 separate APIs can be displayed on the same page?

actions.js

export const getSeverityDistData = (dispatch, urlqueryStr) => {
handleFetch(
    {
        ...getSeverityDist(),
        urlqueryStr,
    }, // fetch params
    (res) => {
        dispatch({
            type: ActionTypes.GET_DASHBOARD_LIST_SUCCESS,
            payload: {
                data: res.data,
                isLoading: false,
                onError: false,
            },
        });
    },
    (e) => {
        dispatch({
            type: ActionTypes.GET_DASHBOARD_LIST_ERROR,
            payload: {
                errorMsg: e.message,
                isLoading: false,
            },
        });
    },
    (loading) => {
        dispatch({
            type: ActionTypes.GET_DASHBOARD_LIST_LOADING,
            payload: loading,
        });
    }
);};
export const getGroupData = (dispatch, urlqueryStr) => {
handleFetch(
{
    ...getGruop(),
    urlqueryStr,
},//...sameOperations SameActionTypes...}

reducers.js



const setChartsData = (state, action) => ({
    ...state,
    data: [...action.payload.data],
    isLoading: action.payload.isLoading,
    onError: action.payload.onError,
});

const setLoading = (state, action) => ({
    ...state,
    isLoading: action.payload,
});

const setTimeOut = (state, action) => ({
    ...state,
    isTimeout: action.payload,
});

const onError = (state, action) => ({
    ...state,
    onError: action.payload.errorMsg,
    isLoading: action.payload.isLoading,
});

const initialState = {
    data: [],
    isLoading: false,
    isTimeout: false,
    onError: '',
};

export default (state = initialState, action) => {
    switch (action.type) {
        case ActionTypes.GET_DASHBOARD_LIST_SUCCESS:
            return setChartsData(state, action);
        case ActionTypes.GET_DASHBOARD_LIST_LOADING:
            return setLoading(state, action);
        case ActionTypes.GET_DASHBOARD_LIST_TIME_OUT:
            return setTimeOut(state, action);
        case ActionTypes.GET_DASHBOARD_LIST_ERROR:
            return onError(state, action);
        default:
            return state;
    }
};

Let me tell you briefly what I want to do. Consider 2 charts on one page. The data coming to these charts is from different api but according to the same filter by the ui. For example, the user will select certain parameters from the filter section and a query will be sent to the APIs according to this filter status, each API will return a data of its own and these different data will be displayed in different graphs on the same page. What I want to do is to separate the data from the API by graphs. When I make a transaction as I wrote above, the values I withdraw from the store change. I guess whichever one comes up overwrites the other. How can I get out of this situation?

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda