因此,在下面的代码中,提示用户将文本输入到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})
})));
}
}
});发布于 2020-05-26 06:32:16
我觉得你错过了偏执狂。将this.onPressUpdate;替换为this.onPressUpdate();。
https://stackoverflow.com/questions/62015669
复制相似问题