【发布时间】:2017-05-29 22:50:40
【问题描述】:
我正在使用 Redux 制作一个简单的商店,不幸的是它抛出了这个错误:
Cannot convert undefined or null to object
浏览器指向导入Redux的那一行
import * as redux from "redux"
我也尝试过以这种方式导入它,但它给出了同样的错误 从“redux”导入 { createStore }
这是代码:
import * as redux from "redux"
let reducer = (state ={}, action) =>{
switch(action.type) {
case "ADD_POLL":
return {
polls: [
...state.polls,
action.poll
]
}
default:
return state
}
}
let store = redux.createStore(reducer)
store.subscribe(()=>{
let currentState = store.getState()
console.log(currentState)
})
store.dispatch({
type: "ADD_POLL",
poll: {
id: 1,
title: "What's your fav Color",
votes: 230
}
})
【问题讨论】:
标签: javascript reactjs redux react-redux