I have the following code in which the first console.log returns the current number of patients, while the console.log inside the nextPage() function returns the previous value of the number of patients.
How can I solve this so that the number of patients inside the nextPage() function is the current one?
const pacients =
data?.getPacients?.map((pacient) =>
AdminPacientEntry({
pacient,
push,
removerPacient: () => {
setPacientSelectedToDelete(pacient);
},
})
) ?? [];
console.log(pacients)
const nextPage = (page) =>{
console.log(pacients)
if(pacients.length < 10){
setCanNextPage(false)
} else{
setCanNextPage(true)
}
setCanPreviousPage(true)
setPageNumber(page)
}