React component sends API call again whenever the homepage component loads with default empty values… I want whenever someone go to the settings page and came back without changes in settings, no new API Call will be sent. But if the user came from settings page after changing settings, then a new API Call will be sent according to changes… I don't want to use Session or local storage… Because it's a random User API, so if I store there it would not be change after user reloads the Page.
const users = useSelector((state) => state.users);
const loading = useSelector((state) => state.loading);
const search = useSelector((state) => state.search);
const nationlity = useSelector((state) => state.nationlity);
const [hasMore, setHasMore] = useState(true);
useEffect(() => {
if (nationlity) {
fetchUseresWithNationality(nationlity);
} else {
fetchUser();
}
}, []);
const loadMoreUsers = () => {
if (users.length <= 999) {
if (nationlity) {
fetchMoreUseresWithNationality(nationlity);
} else {
fetchMoreUsers();
}
} else {
setHasMore(false);
}
};
return (<>My Content</>)
};