K
K
kirillleogky2021-07-30 19:17:05
redux
kirillleogky, 2021-07-30 19:17:05

How to rewrite the value of another in one reducer?

There is an action:

export const SET_SSR_PROPS = 'SET_SSR_PROPS';

export const setSsrProps = response => ({
    type: SET_SSR_PROPS,
    payload: response
});


And reducer:
import { createReducer } from '../storeUtils';
import { SET_SSR_PROPS } from '../actions/ssrActions';

const initialState = {};

const setSsrProps = (state, action) => ({
    ...action.payload
});

export default createReducer(initialState, {
    [SET_SSR_PROPS]: setSsrProps
});


My index.js in reducer:
import { combineReducers } from 'redux';
import orderData from './orderReducer';
import prevSsrProps from './ssrReducer';

const rootReducer = combineReducers({
    orderData,
    prevSsrProps
});

export default rootReducer;


Question - How can I replace the field with data from orderData in the editor when calling this action (setSsrProps)?


To for example:
console.log(store.orderData);  <--------- данные из редюсера orderData   orderData !== this.props.prevSsrProps
setSsrProps(this.props.prevSsrProps);     <----------заменит прошлые даннные в store.orderData на this.props.prevSsrProps
console.log(store.orderData);  <--------- данные из редюсера orderData   orderData === this.props.prevSsrProps

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2021-07-30
@kirillleogky

Handle this action in orderData and do what you need there. And the prevSsrProps reducer is not needed at all.
The store does not have a setState method , what you want cannot be done in one action. But you can process the action in each of your reducers and replace the part of the store for which it is responsible.
Well, either through crutches and bicycles to recreate the whole story in general, but this is a bad decision.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question