0

I'm trying to add a doc on Firebase using the following script:

import { colors } from "@material-ui/core";
import React, {useEffect, useState} from "react";
import { View, Text, Button, SafeAreaView , Pressable, TextInput} from "react-native";
import firebase from "../database/firebase";
import { doc, setDoc } from "firebase/firestore";
import 'firebase/firestore';

const RegisterPage = (props) => {
    
    const [password, setPassword] = useState("");

    const [users, setUsers] = useState([]);

    useEffect(() => {
        const users = [];
        firebase.db.collection('Users').onSnapshot(querySnapshoot => {
            querySnapshoot.docs.forEach(doc => {
                users.push(doc.data())
            });

            setUsers(users);
        });
    },[]);

    LoguejarUsuari = ()=> {

        console.log(password);

        firebase.db.collection('Users').add({
            password: password,
        }).then(() => alert("menu item is posted"))
        .catch((error) => alert("error: " + error));

    }

    return(
        <SafeAreaView style={{flex:1}} >
            <TextInput style={{borderColor:colors.black, borderWidth:2}} value = {password} secureTextEntry={true} onChange={(password)=> {setPassword(password.currentTarget)}}></TextInput>
            <Button title="Register" onPress={() => LoguejarUsuari()}></Button>
        </SafeAreaView>
    )
}
export default RegisterPage

But for some reason the password field returns a ReactNativeFiberHostComponent instead of a String, giving me the error:

FirebaseError: Function addDoc() called with invalid data. Unsupported field value: a custom ReactNativeFiberHostComponent object (found in field password in document Users/raZgtnex66D1VkEbhWZD)

Does anyone know how to fix this error? It used to work until five minutes ago, but without touching anything related it stopped working. I've tried with password.target and password alone but both return the same object too.

Brainstorm
  • 25
  • 1
  • 8
  • Hi @Brainstorm, could you please check this threads: [1](https://stackoverflow.com/questions/41921376/react-native-handle-change-of-input-with-state) [2](https://stackoverflow.com/questions/39723391/passing-react-text-field-input-values-as-parameters-to-a-method) and see if it helps. – Marc Anthony B Mar 09 '22 at 09:50
  • Thanks, I should've used the OnChangeText instead of OnChange. – Brainstorm Mar 14 '22 at 18:19

0 Answers0