Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!