【发布时间】:2020-05-26 06:05:52
【问题描述】:
所以在下面的代码中,提示用户将文本输入到 2 个 TextInputs 中,这将更新状态中的数据,当用户点击“保存配置文件更改”按钮或 TouchableOpacity 时,将状态中的数据发送到Firebase 数据库。
这似乎并没有更新数据库。谁能解释一下这里的问题可能是什么?
import React, { Component } from 'react';
import {
StyleSheet,
Text,
TextInput,
View,
Image,
TouchableOpacity
} from 'react-native';
import Fire from '../Fire';
import * as Analytics from 'expo-firebase-analytics';
export default class UpdateProfileScreen extends Component {
constructor(props) {
super(props);
this.state = {
name: 'no name',
about: '',
zoom: '',
net: '',
profile: ''
};
}
onPressUpdate = async () => {
const user = {
name: this.state.name,
profile: this.state.about,
zoom: this.state.zoom
};
await Fire.shared.updateProfile(user);
};
onChangeTextName = name => this.setState({ name });
onChangeProfile = profile => this.setState({ profile });
render() {
return (
<View style={styles.container}>
<View style={styles.header}></View>
<Image style={styles.avatar} source={{uri: 'https://bootdey.com/img/Content/avatar/avatar3.png'}}/>
<View style={styles.body}>
<TextInput
style={styles.nameInput}
onChangeText={this.onChangeTextName}
value={this.state.name}
/>
<TextInput
style={styles.description}
onChangeText={this.onChangeProfile}
value={this.state.profile}
/>
<View style={styles.bodyContent}>
<TouchableOpacity style={styles.buttonContainer} onPress={() => {
Analytics.logEvent('UserZoomButton', {
screen: 'UpdateProfile',
purpose: 'User clicks on "Zoom" button',
});
}}>
<Text>Zoom</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.buttonContainer} onPress={() => {
Analytics.logEvent('SaveProfileChangesButton', {
screen: 'UpdateProfile',
purpose: 'User clicks on "Save Profile Changes" button',
});
this.onPressUpdate;
}}>
<Text>Save Profile Changes</Text>
</TouchableOpacity>
</View>
</View>
</View>
);
}
componentDidMount() {
Fire.shared.getname(net_result =>
Fire.shared.getname(name_result =>
Fire.shared.getprofile(profile_result => {
this.setState({net:net_result, name:name_result, profile:profile_result})
})));
}
}
});
【问题讨论】:
-
控制台有错误吗?承诺的回应是什么?
const response = await Fire.shared.updateProfile(user); -
@NiyasNazar 没有打印任何响应,因此我将 console.log("inside onpressupdate") 放在 onPressUpdate 的开头以打印任何内容,但同样没有打印任何内容。似乎保存配置文件更改按钮甚至没有触发 onpressupdate.... 嗯
标签: reactjs firebase react-native