简体   繁体   English

从 firestore 检索数据时遇到问题“TypeError: this.store is undefined”

[英]having trouble retrieving data from firestore "TypeError: this.store is undefined"

I have been trying to retrieve my data collection from firestore.我一直在尝试从 firestore 检索我的数据集合。 but here is the issue但这是问题所在

error goes like this错误是这样的

  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)

this is my root reducer这是我的根减速器

  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

my project reducer is like this我的项目减速器是这样的

  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

action行动

  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 })
      })
    }
  }

when I was grabbing static data from this projectReducer it was all fine.当我从这个 projectReducer 中获取静态数据时,一切都很好。 But I'm not able to understand where I'm missing in retrieving data from the database.但是我无法理解我在从数据库中检索数据时遗漏的地方。 I tried downgrading react-redux-firebase, react-redux and still it doesn't work.我尝试降级 react-redux-firebase、react-redux 但它仍然不起作用。 Please help me fix this or I need to know if there's any other method I have to choose.请帮我解决这个问题,否则我需要知道是否还有其他方法可以选择。 Thanks in advance!提前致谢!

Where is the action creator for CREATE_PROJECT? CREATE_PROJECT 的动作创建者在哪里?

I had similar issue, mine was TypeError: Cannot read property 'firestore' of undefined , Try using a function as the arg in firestoreConnect instead;我有类似的问题,我的是TypeError: Cannot read property 'firestore' of undefined ,尝试使用一个函数作为 firestoreConnect 中的参数; something like this firestoreConnect(() => [{ collection: 'projects' }])像这样的东西firestoreConnect(() => [{ collection: 'projects' }])

 export default compose( connect(mapStateToProps), firestoreConnect(() => [ { collection: 'projects' } ]) )(Dashboard)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Cloud Firestore 数据库检索数据时出错 - Error retrieving data from Cloud Firestore database 从 firebase firestore 检索数据列表时出错 - Error retrieving a list of data from firebase firestore 从 Firestore 检索数据后,CollectionView 未重新加载 - CollectionView not reloading after retrieving data from Firestore 从一个 firestore 文档中检索数据以查询另一个 - Retrieving data from one firestore document to query another 及时从 Firestore 中检索数据(在 Widget build(BuildContext context) 之外) - Retrieving Data From Firestore in time (outside of Widget build(BuildContext context) ) 在 ListView 中检索 Firestore 数据但失败 - Retrieving Firestore data in ListView but Failing 类型错误:snap.data 不是 function - Firestore 数据库 - TypeError: snap.data is not a function - Firestore Database 如何从 firebase firestore 获取数据并将数据存储在 useState 钩子中 - How to fetch data from firebase firestore and store the data in useState hook Expo 项目类型错误:未定义不是 object(评估“_firebase.default.firestore”) - Expo project TypeError: undefined is not an object (evaluating '_firebase.default.firestore') 无法从 React-Native-Firebase(v6) Firestore 获取数据:undefined 不是函数(靠近“...this._firestore.native.collectionGet...”) - Can't get data from React-Native-Firebase(v6) Firestore: undefined is not a function (near '...this._firestore.native.collectionGet...')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM