【发布时间】:2020-01-05 09:52:43
【问题描述】:
它适用于第一次单击,但是当我再次单击它以取消选择它时,它显示错误:
state.selectedStudents.includes 不是函数。 (在 'state.selectedStudents.includes(action.item)', 'state.selectedStudents.includes' 未定义)
import {
SELECT
} from "../actions/postActionTypes";
const initialState = {
students: ['Aditya', 'Rohan', 'Hello'],
selectedStudents: []
}
const selectReducer = (state = initialState, action) => {
switch (action.type) {
case SELECT:
return {
...state,
selectedStudents: state.selectedStudents.includes(action.item) ? state.selectedStudents.splice(state.selectedStudents.indexOf(action.item), 1) : state.selectedStudents.push(action.item)
}
default:
return state;
}
}
export default selectReducer;
【问题讨论】:
标签: reactjs react-native redux react-redux