为了账号安全,请及时绑定邮箱和手机立即绑定

为什么它返回空值?

为什么它返回空值?

扬帆大鱼 2023-05-25 17:18:13
嗨,我正在尝试学习 firebase。现在我正在尝试关注 github 文档中的内容。 这是我的 index.js 文件const rfConfig = {}; // optional redux-firestore Config Options// Your web app's Firebase configurationconst 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 Firebasefirebase.firestore();// Add reduxFirestore store enhancer to store creatorconst createStoreWithFirebase = compose(  reduxFirestore(firebase, rfConfig), // firebase instance as first argument, rfConfig as optional second)(createStore);// Add Firebase to reducersconst rootReducer = combineReducers({  firestore: firestoreReducer,});// Create store with reducers and initial stateconst initialState = {};const store = createStoreWithFirebase(rootReducer, initialState);ReactDOM.render(  <React.StrictMode>    <Provider store={store}>    <App />    </Provider>  </React.StrictMode>,  document.getElementById('root'));我的文件夹有 3 个组件。1 用于添加待办事项。1 用于显示待办事项。& 最后一个是前两个的组合
查看完整描述

1 回答

?
largeQ

TA贡献2039条经验 获得超7个赞

您需要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')

);

查看完整回答
反对 回复 2023-05-25
  • 1 回答
  • 0 关注
  • 78 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信