[英]having trouble retrieving data from firestore "TypeError: this.store is undefined"
我一直在嘗試從 firestore 檢索我的數據集合。 但這是問題所在
import React, { Component } from 'react'
import Notification from './Notification.js'
import ProjectList from '../projects/ProjectList'
import { connect } from 'react-redux'
import { compose } from 'redux'
import { firestoreConnect } from 'react-redux-firebase'
class Dashboard extends Component {
render() {
//console.log(this.props)
const { projects } = this.props
return(
<div className="dashboard container">
<div className="row">
<div className="col s12 m6">
<ProjectList projects={projects} />
</div>
<div className="col s12 m5 offset-m1">
<Notification />
</div>
</div>
</div>
)
}
}
export default compose(
firestoreConnect(['projects']),
connect((state) => ({
projects: state.firestore.ordered.projects
}))
)(Dashboard)
這是我的根減速器
import authReducer from './authReducer'
import projectReducer from './projectReducer'
import { combineReducers } from 'redux'
import { firestoreReducer } from 'redux-firestore'
const rootReducer = combineReducers({
auth: authReducer,
project: projectReducer,
firestore: firestoreReducer
})
export default rootReducer
我的項目減速器是這樣的
const initState = {
projects: [
{id: '0', title: 'do some JavaScript', content: 'blah blah blah...'},
{id: '1', title: 'grab some vegitables', content: 'blah blah blah...'},
{id: '2', title: 'have a cup of coffee', content: 'blah blah blah...'}
]
}
const projectReducer = (state = initState, action) => {
switch (action.type) {
case 'CREATE_PROJECT':
console.log('project is', action.project)
return state
case 'CREATE_PROJECT_ERR':
console.log('create project error', action.err)
return state
default:
return state
}
}
export default projectReducer
行動
export const createProject = (project) => {
return (dispatch, getState , { getFirebase, getFirestore }) => {
// console.log('project: ', project)
// adding data to firestore
const firestore = getFirestore()
firestore.collection('projects').add({
...project,
authorFirstName: 'Herold',
authorSecondName: 'Finch',
authorId: 111,
createdAt: new Date()
}).then(() => {
dispatch({type:'CREATE_PROJECT', project })
}).catch((err) => {
dispatch({type:'CREATE_PROJECT_ERR', err })
})
}
}
當我從這個 projectReducer 中獲取靜態數據時,一切都很好。 但是我無法理解我在從數據庫中檢索數據時遺漏的地方。 我嘗試降級 react-redux-firebase、react-redux 但它仍然不起作用。 請幫我解決這個問題,否則我需要知道是否還有其他方法可以選擇。 提前致謝!
CREATE_PROJECT 的動作創建者在哪里?
我有類似的問題,我的是TypeError: Cannot read property 'firestore' of undefined
,嘗試使用一個函數作為 firestoreConnect 中的參數; 像這樣的東西firestoreConnect(() => [{ collection: 'projects' }])
export default compose( connect(mapStateToProps), firestoreConnect(() => [ { collection: 'projects' } ]) )(Dashboard)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.