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
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.