Im trying to add a new data and put it at the top of the array that I got from an API. The problem is that the new data is still at the end of the array and it only renders the new data instead of all of it even though the console.log output all of the data. I know the problem is not the style because it was able to render properly if I didn't add a new data.
This is how I add the new data:
fetch()
**********
.then((result) => {
setListTab(result);
setListTab(listTab => [listTab, {id: 18, name: "All", ...listTab}]);
console.log(listTab);
<ScrollView
showsHorizontalScrollIndicator={false}
horizontal={true}>
{listTab.map(item => (
<TouchableOpacity key={item.id}
activeOpacity={1}>
<Text>{item.name}</Text>
</TouchableOpacity>
))}