I have a stata which fills by fetched data from API. here is my code:
Now I wanna add new data to first of my table. but I don't know how to do it:
Here new data will push to end of table :(
Can everyone help me?
CodePudding user response:
This will push the data to be the last in the array:
const tempArray=allClient;
tempArray.push(data)
setAllClient([...tempArray])
This will put the data to be the first in the array:
const tempArray=allClient;
tempArray.unshift(data)
setAllClient([...tempArray])
CodePudding user response:
It was helpful for me
setAllClient(currentArray => [data, ...currentArray]);