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

129
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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