Hud*_*son 4 firebase reactjs expo google-cloud-firestore
每当我单击代码上的提交按钮将数据上传到我的 firebase 数据库时,我都会收到此错误:
ERROR [2024-01-21T03:39:39.733Z] @firebase/firestore: Firestore (10.7.2): INTERNAL UNHANDLED ERROR: TypeError: Cannot read property 'includes' of undefined
我尝试卸载节点模块,特别是 firebase,但没有任何效果。我尝试创建一个新的 firebase 帐户,但仍然无法正常工作。我想不明白。
import { StyleSheet, Text, View, TextInput, Button } from 'react-native';
import { getAuth } from 'firebase/auth';
import { getFirestore, doc, setDoc } from 'firebase/firestore';
import app from '../config/FirebaseConfig'; // Adjust this path as necessary
const DataInput = () => {
const [monthOrderTotal, setMonthOrderTotal] = useState('');
const [monthDollarAmount, setMonthDollarAmount] = useState('');
const firestore = getFirestore(app);
const auth = getAuth();
const handleSave = async () => {
const user = auth.currentUser;
if (user) {
try {
const userData = {
monthOrderTotal,
monthDollarAmount
};
// Merge the new data into the existing document or create a new document if it doesn't exist
await setDoc(doc(firestore, 'users', user.uid), userData, { merge: true });
console.log('Data saved successfully');
} catch (error) {
console.error('Error saving data: ', error);
}
} else {
console.error('No user logged in');
}
};
return (
<View style={styles.container}>
<Text>Data Input Screen</Text>
<TextInput
style={styles.input}
placeholder="Month Order Total"
value={monthOrderTotal}
onChangeText={setMonthOrderTotal}
keyboardType="numeric"
/>
<TextInput
style={styles.input}
placeholder="Month Dollar Amount"
value={monthDollarAmount}
onChangeText={setMonthDollarAmount}
keyboardType="numeric"
/>
<Button title="Save" onPress={handleSave} />
</View>
);
};
export default DataInput;
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
width: '80%'
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
958 次 |
| 最近记录: |