gpt4 book ai didi

javascript - TypeError : _this. store.getState 不是从 Redux 使用连接时的函数

转载 作者:行者123 更新时间:2023-11-30 08:31:27 29 4
gpt4 key购买 nike

当我第一次使用 node app.js 运行服务器时,一切都很好,我得到 listening on 5050。然后我转到 localhost:5050/并收到这些警告在服务器运行的控制台中。

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:5050/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,但是您随后在 app.js 中通过 CommonJS 要求它line #11 .

这当然很好,但您需要在需要时访问默认属性。更新行如下:

// Old
const store = require('./src/store.js')

// New
const store = require('./src/store.js').default

2。在服务器上调用文档

关于 line #41 src/components/BallerViews.jsx 您正在访问该文档,该文档不存在于服务器上。一个快速的解决方法是将该行包装在一个条件中:

// Old
document.body.style.backgroundColor = '#0e0e13'

// New
if (typeof document !== 'undefined') {
document.body.style.backgroundColor = '#0e0e13'
}

关于javascript - TypeError : _this. store.getState 不是从 Redux 使用连接时的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37290372/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com