将Firebase连接到React应用程序时如何解决“元素类型无效”

时间:2019-08-19 23:37:58

标签: reactjs firebase redux react-redux

使用react和redux设置Firebase / firestore的问题。正在阅读http://docs.react-redux-firebase.com/history/v3.0.0/docs/getting_started.html上的所有文档,并且无法呈现该应用程序并获得错误“元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记了从定义文件中导出组件,或者可能混淆了默认导入和命名导入。”

删除ReactReduxFirebaseProvider可以使我的应用程序呈现,但是它不会连接到数据库。我已经检查了所有默认值并命名了导出,但是仍然找不到问题。

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import * as serviceWorker from './serviceWorker';
import App from './App';
import { createFirestoreInstance } from 'redux-firestore';
import { createStore, applyMiddleware, compose } from 'redux';
import { firebase} from './config/fbConfig';
import { Provider } from 'react-redux';
import { ReactReduxFirebaseProvider} from 'react-redux-firebase';
import rootReducer from './store/reducers/rootReducer';
import thunk from 'redux-thunk';

// react-redux-firebase config
const rrfConfig = {
  userProfile: 'users',
  useFirestoreForProfile: true
};

const store = createStore(
  rootReducer,
  compose(
  applyMiddleware(thunk)
));

const rrfProps = {
  firebase,
  config: rrfConfig,
  dispatch: store.dispatch,
  createFirestoreInstance
};

ReactDOM.render(<Provider store={store}><ReactReduxFirebaseProvider {...rrfProps}><App/></ReactReduxFirebaseProvider></Provider>, document.getElementById('root'));

serviceWorker.unregister();

fbConfig

import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';

const fbConfig = {}; // object containing my Firebase config

// Initialize Firebase
firebase.initializeApp(fbConfig);

const firestore = firebase.firestore();
const auth = firebase.auth();

export {
  firebase,
  firestore,
  auth
};

我是刚接触Firebase的人,对反应和还原的反应还很新,所以可能犯了一个简单的错误,但是在盯着这个错误数小时后,我找不到解决方案。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

对我来说,解决方案是在项目的根目录中打开终端并运行:

  npm install react-redux-firebase@next