Answer the question
In order to leave comments, you need to log in
How to return value of dynamic reducer?
There is a reducer (this version of the code is not working):
const initialState = {
param1: '1',
param2: '2',
param3: {
paramParam1: '4',
paramParam2: '5' // в param3 всегда изменяется только paramParam2
}
}
const reducer = (state = initialState, action) => {
switch (action.type) {
case 'EXAMPLE':
if (action.name === 'param1' || 'param2') {
state[action.name] = action.value
} else {
state[action.name].paramParam2 = action.value
}
return state
}
default:
return state
}
export const actionCreator = (value, name) => ({ type: 'EXAMPLE', value: value, name: name })
// в name приходит свойство, в value - значение
return {
...state,
action.name: action.value
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question