首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未用新数据更新

未用新数据更新
EN

Stack Overflow用户
提问于 2020-05-26 06:05:52
回答 1查看 236关注 0票数 0

因此,在下面的代码中,提示用户将文本输入到2 TextInputs中,当用户单击“保存配置文件更改”按钮或TouchableOpacity时,该文本将更新状态中的数据,该按钮将状态中的数据发送到Firebase数据库。

不过,这似乎并没有更新数据库。有人能说明一下这里的问题是什么吗?

代码语言:javascript
复制
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})
        })));
  }
}
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-26 06:32:16

我觉得你错过了偏执狂。将this.onPressUpdate;替换为this.onPressUpdate();

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62015669

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档