javascript - React configureStore2.default.firestore 不是一个函数
问题描述
我很抱歉打开这篇文章 - 我知道还有其他人。我可能已经从其他帖子中尝试了 20 种不同的设置组合,但我无法通过它。任何帮助将不胜感激。
我收到此错误:
configureStore2.default.firestore 不是函数
动作文件:
import firebase from '../store/configureStore';
.....
export const setTweets = (tweets) => ({
type: 'SET_TWEETS',
tweets
});
export const startSetTweets = () => {
return (dispatch, getState) => {
const uid = getState().auth.uid;
console.log("uid = ", uid);
const postsRef = firebase
.firestore() // <---- this line causes the error
.collection("posts");
从配置商店
import firebase from 'firebase/app';
import 'firebase/auth'
import 'firebase/firestore'
..........
firebase.initializeApp(firebaseConfig)
firebase.firestore().settings({ timestampsInSnapshots: true })
.......
export { googleAuthProvider, firebase, store as default}
来自 package.json
"firebase": "^8.1.1",
"redux": "3.7.2",
"redux-firestore": "0.14.0",
解决方案
您似乎正在导入默认导出configureStore
,store
但它看起来像您想要的firebase
那样。
如果是这种情况import { firebase } from '../store/configureStore';
,请在您的操作文件中使用。
所以你的代码会这样:
import { firebase } from '../store/configureStore';
// .....
export const setTweets = (tweets) => ({
type: 'SET_TWEETS',
tweets
});
export const startSetTweets = () => {
return (dispatch, getState) => {
const uid = getState().auth.uid;
console.log("uid = ", uid);
const postsRef = firebase
.firestore()
.collection("posts");
在此处阅读有关命名导出的更多信息:https ://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
推荐阅读
- python - Python优化了大多数余弦相似向量
- c# - 是否可以将 winforms 状态条和进度条转换为 wpf 状态栏?
- mysql - Mysql查询以获取第一个位置的特定ID
- ruby - IRB 要求 mongo 失败无法加载此类文件——mongo
- oop - 如何在 Dart 中实现继承?
- xml - 转换文件根据子节点的文本值替换整个父节点 - XML Transform
- vb.net - 如何在 DatagridView Checkbox vb.net 中保持选中复选框
- rollup - 如何使用 Rollup 插件挂钩的返回承诺?
- api - 在 .net 核心 web api 中存储 JWT 令牌的位置?
- ios - React Native iOS 空白白屏和 EXC_BAD_ACCESS (code=EXC_I386_GPFLT)