为什么它返回空值?

嗨,我正在尝试学习 firebase。现在我正在尝试关注 github 文档中的内容。 

这是我的 index.js 文件

const rfConfig = {}; // optional redux-firestore Config Options


// Your web app's Firebase configuration

const firebaseConfig = {

  apiKey: 'something',

  authDomain: 'something',

  databaseURL: 'something',

  projectId: 'something',

  storageBucket: 'something.com',

  messagingSenderId: 'something',

  appId: '1:something',

  measurementId: 'G-something',

};


firebase.initializeApp(firebaseConfig);


// Initialize Cloud Firestore through Firebase

firebase.firestore();


// Add reduxFirestore store enhancer to store creator

const createStoreWithFirebase = compose(

  reduxFirestore(firebase, rfConfig), // firebase instance as first argument, rfConfig as optional second

)(createStore);


// Add Firebase to reducers

const rootReducer = combineReducers({

  firestore: firestoreReducer,

});


// Create store with reducers and initial state

const initialState = {};

const store = createStoreWithFirebase(rootReducer, initialState);


ReactDOM.render(

  <React.StrictMode>

    <Provider store={store}>

    <App />

    </Provider>

  </React.StrictMode>,

  document.getElementById('root')

);

我的文件夹有 3 个组件。1 用于添加待办事项。1 用于显示待办事项。& 最后一个是前两个的组合



扬帆大鱼
浏览 121回答 1
1回答

largeQ

您需要ReactReduxFirebaseProvider在组件树的顶部附近渲染一个。这就是useFirebase试图访问的内容,因此如果没有,您将无法定义。const rrfConfig = {  userProfile: 'users'  // useFirestoreForProfile: true // Firestore for Profile instead of Realtime DB}const rrfProps = {  firebase,  config: rrfConfig,  dispatch: store.dispatch  // createFirestoreInstance // <- needed if using firestore}ReactDOM.render(  <React.StrictMode>    <Provider store={store}>      <ReactReduxFirebaseProvider {...rrfProps}>        <App />      </ReactReduxFirebaseProvider>    </Provider>  </React.StrictMode>,  document.getElementById('root'));
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript