【问题标题】:save few state values to firestore react保存一些状态值到 Firestore 反应
【发布时间】:2019-05-18 03:49:19
【问题描述】:

我想将状态值的一些细节保存到 Firestore。我怎样才能做到这一点?

状态详情

state = {
    loading: false,
    sp_name: '',
    sp_Phone: '',
    sp_Role: '',
    sp_Location: '',
    sp_Service: '',
    sp_country: '',
    sp_message: '',
    sp_License: ''
  }

我不想将加载状态保存到 Firestore。

处理提交事件。

 handleSubmit = (e) => {
    e.preventDefault();
    this.setState({ loading: true })
    let uid = this.props.auth.uid;
    this.props.UpdateUser(uid, this.state)
    this.setState({ loading: false })
    toast("Registered Successfully.!", { type: toast.TYPE.INFO, autoClose: 5000 });


  }

【问题讨论】:

    标签: reactjs state


    【解决方案1】:
    handleSubmit = (e) => {
        e.preventDefault();
        this.setState({ loading: true })
        const stateObj = this.state;
        delete stateObj['loading'];
        let uid = this.props.auth.uid;
        this.props.UpdateUser(uid, stateObj)
        this.setState({ loading: false })
        toast("Registered Successfully.!", { type: toast.TYPE.INFO, autoClose: 5000 });
      }
    

    【讨论】:

      猜你喜欢
      • 2020-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 1970-01-01
      • 2020-08-28
      相关资源
      最近更新 更多