将firebase.initializeApp作为道具传递到我的路由器组件 - React-Native

时间:2017-03-30 11:38:54

标签: firebase react-native

这是我第一次使用firebase,我想知道如何将const firebaseApp传递到<Provider / <Router/>组件,或者最好的方法是什么?我正在尝试将其传递到主页组件之后的 MainPage 组件。干杯!

import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import * as firebase from 'firebase';
import ReduxThunk from 'redux-thunk';
import reducers from './reducers';
import Router from './Router';


class App extends Component {
  componentWillMount() {
    const config = {
      apiKey: 'xxx',
      authDomain: 'xxx',
      databaseURL: 'xxx',
      storageBucket: 'xxx',
      messagingSenderId: 'xxx'
  };
  // firebase.initializeApp(config);
  const firebaseApp = firebase.initializeApp(config);
  }

  render() {
    const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));

    return (
      <Provider store={store}>
        <Router initializeApp={this.initApp} />
      </Provider>
    );
  }
}

export default App;

0 个答案:

没有答案