Answer the question
In order to leave comments, you need to log in
How to correctly change the property of an array element?
How to do it correctly to copy the state, but at the same time change active to the opposite one on the incoming id?
const CHECKED_POST = 'CHECKED_POST'
let initialState = {
checkboxes: [
{id: 1, message: 'Встать рано утром', active: false},
{id: 2, message: 'Скушать вкусный завтрак', active: false},
{id: 3, message: 'Провести тренировку', active: false},
{id: 4, message: 'Поработать', active: false},
{id: 5, message: 'Встретиться с друзьями', active: false}
]
}
const todoReducer = (state= initialState, action) => {
switch (action.type) {
case CHECKED_POST: {
return {
...state,
checkboxes: [...state.checkboxes.filter((id) => {
if (id !== action.id) {
return {
//Как правильно?
}
}
})]
}
}
default:
return state
}
}
export const checkedPost = (id) => (dispatch) => dispatch({type: CHECKED_POST}, id)
export default todoReducer
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