React 从 firebase 读取,出现错误
2018-12-18
1360
我尝试从 firebase 集合中获取数据,但出现错误,有人能帮忙吗? 我收到此错误
Error: Context from react-redux not found. If you are using react-redux v6 a v3. . version of react-redux-firebase is required. Please checkout the v3 migration guide:
这是我的代码。
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"
]
}
3个回答
错误很明显,您使用的是
react-redux-firebase
:
^2.2.5
,而您需要使用 v3,因为您使用的是
react-redux
:
^6.0.0
。
您必须更新
react-redux-firebase
Kabbany
2018-12-18
如果您按照某人的示例进行操作,而不是构建生产应用程序,则可以切换到 react-redux 5.1.1。
只需在 package.json 中将
"react-redux": "^6.0.0",
更改为
"react-redux": "^5.1.1",
,然后运行
npm install
。
Alesh Houdek
2019-01-10
上面的@kabanny 非常正确。
如果您确实要使用支持上下文 API 的下一个版本的
react-redux-firebase
,请自行承担风险执行以下操作。
npm install react-redux-firebase@next
另请查看 迁移指南
Philippe Moore
2019-02-13