Home > Enterprise >  How change class component of switch to functional component in react native expo
How change class component of switch to functional component in react native expo

Time:12-02

I have class component that work for switch

 state = {
   
    showMen: this.props.user.showMen,
    showWomen: this.props.user.showWomen,
  }


  updateUser = (key, value) => {
    const {uid} = this.props.user
    firebase.database().ref('Users').child(uid)
      .update({[key]:value})
  }

  render() {
   
    const { showMen, showWomen} = this.state
        <View style={styles.switch}>
          <Text>Show Men</Text>
          <Switch
            value={showMen}
            onValueChange={val => {
              this.setState({showMen:val})
              this.updateUser('showMen', val)
            }}
          />
        </View>
        <View style={styles.switch}>
          <Text>Show Women</Text>
          <Switch
            value={showWomen}
            onValueChange={val => {
              this.setState({showWomen:val})
              this.updateUser('showWomen', val)
            }}
          />
        </View>
      </View>

I want to convert to Hook component and want insert data in to firestore of existing users data may be setDoc() should use but I have problem in changing this class to hook Can someone help me How can change this codes to hook components and insert to firestore thanks you

CodePudding user response:

I've changed it; but I didn't quietly understand what is setDoc() doing?

  • Related