【发布时间】:2018-04-26 20:37:48
【问题描述】:
我正在尝试在 egghead.io 上开设“redux 入门”课程
但是,我不想像他那样在 jsbin 上使用示例代码。
我想将它与我自己的快递服务器一起使用。因为,如果我们在现实生活中根本无法使用“入门”教程,那还有什么意义呢?
这是课程中使用的代码: http://jsbin.com/wuwezo/74/edit?js,console,output
开头是这样的:
const { connect, Provider } = ReactRedux;
const { combineReducers, createStore } = Redux;
所以我正在尝试使这两条线正常工作。
在我的 index.jsx 文件中,在这两行之上,我导入了 react-redux 和 redux,所以:
import ReactRedux from 'react-redux';
import Redux from 'redux';
const { connect, Provider } = ReactRedux;
const { combineReducers, createStore } = Redux;
然后我运行 webpack(我使用 babel loader):它将 bundle.js 文件放在公共目录中(index.html 所在的位置)。 然后我运行 express 服务器,并访问 index.html。
我在控制台中得到了这个: 火狐: "TypeError: _reactRedux2.default 未定义[了解更多]"
铬: “未捕获的类型错误:无法读取未定义的属性‘连接’”
谷歌搜索firefox错误,我什么也没得到。
但对于 Chrome,我知道我使用“const {...}”得到了未定义。
这是一个 babel loader 的问题吗?
我错过了什么?
【问题讨论】:
-
还可以查看github.com/facebook/create-react-app - 让您专注于 React 而无需花时间进行配置。