我得到的错误是[Unhandled promise rejection: ReferenceError: Can't find variable: atob]
。
还有我的屏幕代码:
import React, { Component } from "react";
import { View, StatusBar, Text } from "react-native";
import firebase from "firebase";
import "firebase/firestore";
import { RowItem } from "../components/RowItem";
import { Header, Left, Right, Icon } from "native-base";
const styles = {
container: {
flexDirection: "row",
flexWrap: "wrap",
padding: 20
}
};
class QuizIndex extends Component {
constructor(props) {
super(props);
this.state = {
docs: []
};
}
async componentDidMount() {
await this.quizes();
}
quizes = async () => {
let result = await firebase
.firestore()
.collection("quiz")
.where("parentId", "==", "")
.get()
.then(r => {
console.log("fine");
})
.catch(e => {
console.log("Not fine");
});
const docs = result.docs.map(doc => {
return { uid: doc.id, ...doc.data() };
});
return this.setState({ docs });
};
render() {
return (
<View style={styles.container}>
<StatusBar barStyle="dark-content" />
{this.state.docs.map(doc => (
<RowItem
key={doc.uid}
parentId={doc.parentId}
name={doc.title}
color={doc.color}
icon={doc.icon}
onPress={() =>
this.props.navigation.navigate("QuizSub", {
title: doc.title,
color: doc.color,
parentId: doc.uid
})
}
/>
))}
</View>
);
}
}
export default QuizIndex;
在发生此问题的地方我不明白,因为一切正常。您对此有何建议?我用谷歌搜索,但是没有一个解决方案对我有帮助。
答案 0 :(得分:1)
这是Firebase依赖方面的问题
尝试使用7.9.0版,此版本可以正常工作。
yarn add firebase@7.9.0
答案 1 :(得分:0)
我认为,如果您安装了base-64
npm软件包,它将解决,但是还不知道为什么会这样。
yarn add base-64
#or
npm install base-64
在App.js上添加:
import {decode, encode} from 'base-64'
if (!global.btoa) { global.btoa = encode }
if (!global.atob) { global.atob = decode }