When attempting to insert a new data entry at the beginning of an array fetched from an API, I encountered an issue. Despite successfully adding the new data to the array, it appeared at the end rather than the top. Additionally, only the new data was rendered instead of the entire array, even though all the data was being logged in the console. This problem persists regardless of the applied style.
The following code snippet illustrates 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>
))}