Sets value for item selected by path
Returns: object
- action object
Params
- path
number
|string
|Array.<(string|number)>
- path to be updated (array of items or dot-separated string can be provided) - value
any
- value to set in specified path
Description
import { ACTIONS, reducer } from 'general-reducer';
const state = {
a: {
a1: 1,
a2: 2
},
b: {
b1: 3,
b2: 4
}
};
const updated = reducer(state, ACTIONS.set('b.b1', 5));
// or
const updated = reducer(state, ACTIONS.set([ 'b', 'b1' ], 5));
As a result we will receive new object with structure below:
{
a: {
a1: 1,
a2: 2
},
b: {
b1: 3,
b2: 5
}
}