I'm trying to update a state as soon as the page comes to focus in react native with react native navigation, but if I log the value it still results in the old one.
useFocusEffect(
React.useCallback(() => {
if (route.params?.key !== null) {
setKey(route.params?.key);
console.log(route.params?.key) //These two console log give different values
console.log(key);
setLastTokenDate(route.params?.date);
}
}, [route.params?.chiave, route.params?.data]),
);