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

130
Vistas
My State Does Change But Components Are Disappear When I Update My State In React Native How To Fıx This?
const DetailedSearchScreen=({ navigation })=> {
  const mydefauthor='no';
  const mydeftitle='data';
  var [dataset, setDataset]=useState({data:[{Author:'Deneme', Title:'yapiyorum'}]});
  return (
    <ScrollView contentContainerStyle={styles.container}>
      
      <TextInput onChangeText={text=>det_author=text} placeholder="Enter Author" style={styles.item_style} onClick={()=>{
       console.log(dataset, "You are the hero!");
      }}/>
      <TextInput onChangeText={text=>det_keyword=text} placeholder="Enter Keyword" style={styles.item_style}/>
      <TextInput onChangeText={text=>det_year=parseInt(text)} placeholder="Year" style={styles.item_style}/>
      <TextInput onChangeText={text=>det_sub_date=text} placeholder="Enter Submission Date As Year-Month-Day" style={styles.item_style}/>

      <TouchableOpacity onPress={()=>{
        var data_=make_search();
        console.log("Data info: ",dataset);
        var item={};
        item['data']=data_;
        setDataset(Object.assign({...dataset, ...item}));
        console.log(dataset, "Yine mi olmadı be");
      }} style={styles.button}><Text>Search</Text></TouchableOpacity>
        <View>  
          {
          dataset['data'].map((item, key)=>{
            console.log(item);
            return(
              <Text>{item['Author']}</Text>
            );
          })}
        </View>
    </ScrollView>
  );
}

part of the code is like that, when I read from the console.log result, it shows that state is changed but my mapped components disappear when I updated the state

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You didn't enter your key prop in the Text element. You should have

<Text key={key}> ... </Text>

Also here you are using the array index as a key and it might cause errors.

You should use something that is unique to that data and will not change (title or author if they are unique and immutable).

The best option would be to have a unique id.

https://reactjs.org/docs/lists-and-keys.html

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