React-Redux-Firebase和Redux-Firestore没有用数据填充我的Redux状态

时间:2018-07-30 15:35:10

标签: react-redux google-cloud-firestore react-redux-firebase

我是使用上述2个库的初学者。我在Cloud Firestore上有一些虚拟员工数据,我想使用react-redux-firebase和redux-firestore获得这些数据。

我已经配置了redux存储并添加到reducer中,但是在我的redux状态下看不到任何员工数据。我的代码中没有看到任何错误。有人可以帮忙吗?谢谢

下面是我的codeandbox链接...这是我创建的用于尝试上述库的非常基本的应用程序

https://codesandbox.io/live/VOxppz

我的Firebase设置

import firebase from "firebase";
import "firebase/firestore";

const firebaseConfig = {
  apiKey: "AIzaSyD564gkWOpSYks8wxOmWNwGsG-555uvBDg",
  authDomain: "test-3babb.firebaseapp.com",
  databaseURL: "https://test-3babb.firebaseio.com",
  projectId: "test-3babb",
  storageBucket: "test-3babb.appspot.com",
  messagingSenderId: "911931804634"
};

firebase.initializeApp(firebaseConfig);
firebase.firestore();

export default firebase;

我的Redux商店

import { createStore, applyMiddleware, compose } from "redux";
import thunk from "redux-thunk";
import { reactReduxFirebase, getFirebase } from "react-redux-firebase";
import { reduxFirestore, getFirestore } from "redux-firestore";

import firebase from "../../config/firebase";
import rootReducer from "../reducers";

// Refer to App.js for wrapping of App component

const rrfConfig = {
  userProfile: "users",
  attachAuthIsReady: true,
  useFirestoreForProfile: true
};

export const configureStore = preloadedState => {
  const middlewares = [thunk.withExtraArgument({ getFirebase, getFirestore })];

  const middlewareEnhancer = applyMiddleware(...middlewares);
  const storeEnhancers = [middlewareEnhancer];
  const composedEnhancer = compose(
    ...storeEnhancers,
    reactReduxFirebase(firebase, rrfConfig),
    reduxFirestore(firebase)
  );

  const store = createStore(rootReducer, preloadedState, composedEnhancer);

  return store;
};

我的Redux Reducer

import { combineReducers } from "redux";
import { firebaseReducer } from "react-redux-firebase";
import { firestoreReducer } from "redux-firestore";

import authReducers from "./authReducers";

export default combineReducers({
  auth: authReducers,
  firebase: firebaseReducer,
  firestore: firestoreReducer
});

1 个答案:

答案 0 :(得分:0)

我忘记了将firestoreConnect连接到我的组件。一旦完成,数据就会流入我的组件。问题解决了。谢谢