我正在尝试从Firebase集合中获取数据,但出现错误,有人可以帮忙吗? 我收到此错误
错误:找不到来自react-redux的上下文。如果您使用react-redux v6,则需要v3。。版本的react-redux-firebase。请查看v3迁移指南:
这是我的代码。
import React, { Component } from 'react'
import Notifications from './Notifications';
import ProjectList from '../projects/ProjectList';
import {connect} from 'react-redux';
import {firestoreConnect} from 'react-redux-firebase';
import {compose} from 'redux';
import { firebaseConnect, isLoaded, isEmpty } from 'react-redux-firebase'
class Dashboard extends Component {
render() {
return (
<div className="dashboard container">
<div className="row">
<div className="col s12 m6"><ProjectList projects={this.props.projects}></ProjectList></div>
<div className="col s12 m5 offset-m1"><Notifications></Notifications></div>
</div>
</div>
)
}
}
const mapStateToProps = (state) =>
{
console.log(state);
return ({projects:state.projectReducer.projects})
}
export default compose(firebaseConnect([
'projects'
]), connect(mapStateToProps)) (Dashboard)
我尝试了此导出,但存在相同的错误
export default compose(connect(mapStateToProps), firestoreConnect([
{collection:'project'}
])) (Dashboard)
这是我的package.json
{
"name": "myproject",
"version": "0.1.0",
"private": true,
"dependencies": {
"firebase": "^5.7.0",
"firedux": "^1.1.0",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"react-redux": "^6.0.0",
"react-redux-firebase": "^2.2.5",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.1",
"redux": "^4.0.1",
"redux-firestore": "^0.6.0",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
答案 0 :(得分:5)
错误非常清楚,您正在使用react-redux-firebase
:^2.2.5
,而您需要使用v3,因为正在使用react-redux
:^6.0.0
。
您必须更新react-redux-firebase
答案 1 :(得分:0)
如果您遵循某人的示例,而不是构建生产应用程序,则可以切换到react-redux 5.1.1。
只需在package.json中将"react-redux": "^6.0.0",
更改为"react-redux": "^5.1.1",
并运行npm install
。
答案 2 :(得分:0)
@kabanny以上是正确的。
如果您确实要使用支持上下文api的下一版react-redux-firebase
,请自担风险。
npm install react-redux-firebase@next
还要签出migration guide
答案 3 :(得分:0)
如果确实使用npm
安装软件包。降级为react-redux-firebase@2.2.5
和react-redux@5.1.1
确实解决了我的问题。注意事项:如果在遵循某人的教程时遇到此类错误,建议您首先确认他们使用的依赖项版本。 npm
会让您陷入困境。