0
我想写一个应用程序,用户可以在其中添加一个项目到集合。用户键入collection-item的名称,并出现该名称的项目。 但是,当我派遣行动addCollection
:减速机不知道我的状态在反应减少
export function addCollection(text) {
console.log("ACTION ADD COLLECTION FIRED");
return {
type: "ADD_COLLECTION",
text
}
}
我减速机:
export default function collection(state = [], action) {
switch(action.type) {
case "ADD_COLLECTION":
return (
Object.assign({}, state, {
collections: [
{
name: action.text,
src:''
},
...state.collections
]
})
);
}
return state
}
出错:
TypeError: Cannot convert undefined or null to object
它有我的减速器6行。我认为减速机不知道我的状态。收集
var initialState = {
collections:[
{
name:"Aenean in justo ante",
src: ''
},
{
name:"Aenean in justo ante",
src: ''
}
],
formIsRender: false
}
const store = createStore(allReducers, initialState)
错误在哪里?