как сделать глубокое копирование state: Нужно у определенного типа у определенного юзера поменять поле даты:
const initialState = {
briefingType:
[{type: 'elevation', users: [
{userid : '1', userName: 'vasia', date: 'thursday'},
{userid: '2' ,userName: 'ivan', date: 'monday'},
{userid: '3' ,userName: 'petro', date: 'false'},
] }
,
{type: 'tools',
users: [
{userid : '1', userName: 'vasia', date: 'sunday'},
{userid: '2' , userName: 'ivan', date: 'false'},
{userid: '3' , userName: 'petro', date: 'monday'},
]
},
],
loading: false,
}
export default function briefingReducer (state = initialState, action) {
switch(action.type){
case SETTYPE:
return{
...state,
loading: true,
briefingType:[...state.briefingType,
state.briefingType.find((el) => el.type=== action.payload.type)
.
]///////???????
}
без редакса эта функция выглядит так:
const addBriedingDate = function(briefingType, type, userName, date){
briefingType.find((el) => el.type===type).users.find((u)=>u.userName===userName).date = date
return briefingType
}