Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

249
Vistas
My app crashes when rendered text input is null. Undefined error REACT NATIVE

How can I improve the below code so that the app is not crashing when the "input" value is null? I know the issue is with "const { input } = route.params;" If I remove it and add some text input, and put it back, the app works. However, on refresh app will crash when the initial value is null. How to implement the if statement?

Here I am rendering "input", which is TextInput:

export const IznajmiScreen = ({navigation, route}) => {
  const { input } = route.params;
  
  return (
    <>
    <SectionContainer>
      <Text>{input}</Text>
    </SectionContainer>
    </>
  );
  };

And here is my text input Screen:

export const OpciPodaciOglasInput = ({navigation}) => {
const [input, setInput] = useState("");
return( 
    <>
    <Button title="Save"
    onPress={()=>navigation.navigate("Rent a car", {input})}/>
   <InputContainer>
   <TextInput style={styles.input} 
    placeholder="300 maximum"
    multiline = {true}
    maxLength={300}
    onChangeText={(text)=> setInput(text)}
    returnKeyType='done'
    value={input}
    onSubmitEditing={()=>{
      navigation.navigate('Rent a car',{input});
      setInput("");
    }}
    />
    </InputContainer>  
    </>
  );
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Have you tried adding a ternary.

<Text>{input === null ? "" : input}<Text>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda