首页 > 解决方案 > 保存一些状态值到 Firestore 反应

问题描述

我想将状态值的一些细节保存到 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 });


  }

标签: reactjsstate

解决方案


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 });
  }

推荐阅读