TypeError:_this.store.getState在使用来自Redux的连接时不是函数
TypeError: _this.store.getState is not a function when using connect from Redux
当我第一次使用node app.js
运行服务器时,一切都很好,我得到了listening on 5050
。然后我转到localhost:55050/,在服务器运行的控制台中收到这些警告。
Warning: Failed propType: Required prop `store.subscribe` was not specified in `Provider`.
Warning: Failed Context Types: Required child context `store.subscribe` was not specified in `Provider`.
组件在那里表现得很好,但一旦我进入localhost:550/ballerviews,我就会在服务器上得到它
TypeError: _this.store.getState is not a function
at new Connect (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react-redux/lib/components/connect.js:133:38)
at [object Object].ReactCompositeComponentMixin.mountComponent (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactCompositeComponent.js:148:18)
at [object Object].wrapper [as mountComponent] (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactPerf.js:66:21)
at Object.ReactReconciler.mountComponent (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactReconciler.js:37:35)
at ReactDOMComponent.ReactMultiChild.Mixin.mountChildren (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactMultiChild.js:241:44)
at ReactDOMComponent.Mixin._createContentMarkup (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactDOMComponent.js:591:32)
at ReactDOMComponent.Mixin.mountComponent (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactDOMComponent.js:479:29)
at Object.ReactReconciler.mountComponent (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactReconciler.js:37:35)
at [object Object].ReactCompositeComponentMixin.mountComponent (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactCompositeComponent.js:225:34)
at [object Object].wrapper [as mountComponent] (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactPerf.js:66:21)
你可以在我的Github上查看整个项目,因为我觉得在那里查看它可以获得最好的理解。
我今天一整天都在想办法解决这个问题,但我做不到。在我尝试在服务器上渲染之前,它运行良好。我很感激你的帮助,如果你需要更多信息来回答这个问题,请告诉我。
只有两个小问题:
1.ES2015模块->CommonJS
您在src/store.js
中使用的是ES2015 export default
,但是您需要通过第11行app.js
中的CommonJS使用它。
当然,这很好,但在需要时,您需要访问默认属性。更新行如下:
// Old
const store = require('./src/store.js')
// New
const store = require('./src/store.js').default
2.在服务器上调用document
在src/components/BallerViews.jsx
的第41行,您正在访问服务器上不存在的文档。一个快速的解决方案是将这条线包装在一个条件中:
// Old
document.body.style.backgroundColor = '#0e0e13'
// New
if (typeof document !== 'undefined') {
document.body.style.backgroundColor = '#0e0e13'
}
相关文章:
- 是否可以将一个函数输入连接到另一个函数调用的文本
- 如何使用密码检测网络中的状态连接
- React Redux错误页面管理
- 如何处理node.js节点mongodb中的连接和查询队列
- Rails-JQueryUIAutcomplete和AJAX不工作,可以't连接到数据库
- 在Redux中,我应该在哪里编写复杂的异步流
- Twilio-显示所有连接参与者的远程参与者视频
- 操作放置在画布上的元素之间的连接
- TypeError:_this.store.getState在使用来自Redux的连接时不是函数
- jQuery UI可排序-多连接列表拖动
- 如何使用offer/answer交换来自两个对等连接的流
- 在 react-redux 中连接时出错
- Redux Saga连接多个发电机进行存储
- React-Redux:当连接到处于状态的数组时无限循环
- 连接在 Redux-react 中无法使用 Stateless 组件
- 如何重构这个Redux连接代码
- 如何以可维护的方式使用React和Redux thunk处理服务器/连接异常
- React Redux-在没有连接的情况下调用调度(不是来自React组件)
- 如何在不必连接后端的情况下创建登录和注册页面(ReactJS+Redux)
- React-Router 组件在连接redux-store后不会应用activeStyle