undefined is not an object (evaluating ' _firebase.firebase.firestore

情到浓时终转凉″ 提交于 2021-01-29 02:40:57

问题


i want to fetch all data from firestore and show on a list

export const fetchAds = () => {
return dispatch => {
firebase
  .firestore()
  .collection("ads")
  .get()
  .then(ads => {
    dispatch({ type: FETCH_ADS, ads });
  });
 };
};

this is my actions file

import * as actions from "../../actions"; 

class HomeScreen extends Component {

 renderAds() {
return this.props.ads.map((ad, index) => {
  return <Cards key={index} ad={ad} />;
 });
}
  function mapStateToProps(state) {
   return {
     ads: state.ads.data
  };
  }

export default connect(
   mapStateToProps
   )(HomeScreen);

this is my list where i can show it but it show me the error undefined is not an object (evaluating ' _firebase.firebase.firestore


回答1:


you should have to firestore from firebase package! like:


import firebase from 'firebase'
import 'firebase/firestore';

export const fetchAds = () => {
return dispatch => {
firebase
  .firestore()
  .collection("ads")
  .get()
  .then(ads => {
    dispatch({ type: FETCH_ADS, ads });
  });
 };
};



来源:https://stackoverflow.com/questions/55808613/undefined-is-not-an-object-evaluating-firebase-firebase-firestore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!