【发布时间】:2018-02-07 06:01:00
【问题描述】:
我正在尝试编写一个应用程序,用户可以在其中将项目添加到集合中。用户键入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 行。我认为 reducer 不知道我的 state.collection
var initialState = {
collections:[
{
name:"Aenean in justo ante",
src: ''
},
{
name:"Aenean in justo ante",
src: ''
}
],
formIsRender: false
}
const store = createStore(allReducers, initialState)
错在哪里?
【问题讨论】:
标签: javascript reactjs redux react-redux jsx