reactjs - 类型错误:firestore.collection 不是函数(React、Redux、Firestore)
问题描述
将 firebase 和 firestore 与 react 集成时,我遇到了这个错误。
我已经关注了新的 react-redux-firebase 文档,但它没有帮助。
错误-> TypeError:firestore.collection 不是函数
这是我收到错误的功能
代码
export const addProductFamily = (productFamilyDetails) => {
return (dispatch, getState, { getFirestore }) => {
console.log("product family details ", productFamilyDetails);
const firestore = getFirestore();
console.log("firestore is ", firestore);
firestore
.collection("productFamilyDetails") <------------ error
.add({
...productFamilyDetails,
})
};
};
这是我设置所有配置的 App.js 文件
应用程序.js
import { Provider } from "react-redux";
import { createStore, applyMiddleware, combineReducers, compose } from "redux";
import thunk from "redux-thunk";
import authReducer from "./store/reducers/auth";
import {
ReactReduxFirebaseProvider,
firebaseReducer,
getFirebase,
} from "react-redux-firebase";
import {
createFirestoreInstance,
firestoreReducer,
getFirestore,
reduxFirestore,
} from "redux-firestore";
import { firebaseConfig } from "./config/fbConfig";
import firebase from "firebase/app";
const rrfConfig = { userProfile: "users", useFirestoreForProfile: true };
const rootReducer = combineReducers({
auth: authReducer,
firebase: firebaseReducer,
firestore: firestoreReducer,
});
const store = createStore(
rootReducer,
compose(
applyMiddleware(thunk.withExtraArgument({ getFirebase, getFirestore })),
reduxFirestore(firebaseConfig, firebase)
)
);
const rrfProps = {
firebase,
config: rrfConfig,
dispatch: store.dispatch,
createFirestoreInstance,
};
ReactDOM.render(
<Provider store={store}>
<ReactReduxFirebaseProvider {...rrfProps}>
<BrowserRouter>
{/* <App /> */}
<Layout />
</BrowserRouter>
</ReactReduxFirebaseProvider>
</Provider>,
document.getElementById("root")
);
我已经删除了不必要的导入
解决方案
您调用 reduxFirestore 时的参数是向后的。改变这个:
reduxFirestore(firebaseConfig, firebase)
对此:
reduxFirestore(firebase, firebaseConfig)
推荐阅读
- r - R - 带有 httr 的 POST json
- node.js - NPM 安装错误:在位置 1 的 JSON 中出现意外的令牌 <,同时在 ' 附近进行解析
- solr - solr 查询在刷新时给出不同的 numFound
- python - 使用 OpenCV 从“Where's Waldo”图片中检测人脸
- ngrx - ngrx 标准化状态选择器
- python - 在 Pandas 中按增量时间移动行
- android - 如何从格鲁吉亚国家/地区上传到谷歌商店(不在列表中)
- xml - 在 pl/sql 上创建大 xml
- android-fileprovider - androidx FILE_PROVIDER_PATHS
- python-3.x - 将参数放在列表中并在定义中返回它们并带有索引