I have add react-hook/exhaustive-deps and Im having issues deciding how to do things.
Let's say that I have a function that does an Ajax call to get user data. If there is an error then it informs the user about it.
const { t } = useTranslation();
const [textErrorKey, setTextErrorKey] = useState();
useEffect(() => {
async function getUser() {
setLoading(true);
try {
const { user } = await queryUser(userId);
setUser(user);
} catch(error) {
setLoading(false);
if(!error.isAuthenticated) {
setTextErrorKey(t('not-authenticated'));
}
}
}
if (id) {
getUser();
}
}, [t, id])
When the user decides to change the language, Does it mean that it will execute this code again ? How can I avoid that ? I don't want a second Ajax call because the language has changed.
I know that I can disable the rule but Im reading everywhere that it is more convenient not to do it. Is there any best practices or blog post related to handling common uses cases for react-hook/exhaustive-deps ?