Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
I want to set state of parent component from child component during onChangeText in react native?

Here I want to setName of parent component's state from child component while onCHangeText but it gives me "TypeError: setName is not a function. (In 'setName(text)', 'setName' is undefined)" error

Here is my Parent Component

const ProfileCreationScreen = () => {
    const [name, setName] = useState()
 


  const userSignup = async () => {
    try {
  
      firestore().collection('users').doc("androiduser_mobile89").set({
        name: name,
      });
      alert("Succesfully Created")
    } catch (error) {
      alert(error);
    }
  };


  return (
    <SafeAreaView>
      <Text>Create your account</Text>
      <Button
        mode="contained"
        onPress={() => userSignup()}>
        Sign Up
      </Button>
      <View style={{ display: "none" }}>
        <NameScreen setName={setName} />
      </View>
    </SafeAreaView>
  )
}

Here is my child component

export const NameScreen = ({ setName, navigation }) => {
return (
  <KeyboardAvoidingView
    enabled
    behavior="padding"
    style={styles.container}>
    <View>
      <Text style={styles.text}>Full Name</Text>
      <TextInput
        style={styles.textField}
        label="Enter your Full Name"
        underlineColor="#FF0074"
        outlineColor="red"
        value={text}
        onChangeText={(text) => setName(text)}
      />
      <Button mode="contained" style={styles.btn} onPress={() => alert(text)}>
        Next
      </Button>
    </View>
  </KeyboardAvoidingView>
);
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda