I am fetching a JSON file and storing it in two arrays and sorting one of them by its rate as it shown below, unfortunately, it sorting the two arrays the recentPro and ratedPro but the desired array to be sorted is ratedPro only
fetch(url)
.then((response) => response.json())
.then((responseJson) => {
this.setState({
recentPro: responseJson.products,
ratedPro:responseJson.products,
},
function() {
//Sort by rate
const ratedpro= this.state.ratedPro.sort(function(a, b) {
return Number(b.rate) - Number(a.rate);
})
this.setState({
ratedPro: ratedpro,
})
})
Flat List
<FlatList
data={this.state.ratedPro}
renderItem={this.mostrated}
keyExtractor={item => item.pro_name}/>
<FlatList
data={this.state.recentPro}
renderItem={this.rederItem}
keyExtractor={item => item.pro_id} />