I wanted to reload data from the server ever time a certain tab is tapped on. useEffect was however not doing this by itself as I expected it would. I found useFocusEffect however
which seems to do what I want.
import { useFocusEffect } from "@react-navigation/native";
useFocusEffect(
React.useCallback(() => {
request(uid);
return () => {
alert("Screen was unfocused");
// Do something when the screen is unfocused
// Useful for cleanup functions
};
}, [])
);
So, this works great in that every time I tap on that tab it fetches the data like I want. However, in the example code it has the 'useful for cleanup functions'. Is there something I should be doing there? I am basically fetching a list of users.