-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdef763
commit f597a5e
Showing
3 changed files
with
26 additions
and
19 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
template/src/hooks/use-invalidate-queries-on-language-change.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import { useEffect, useRef } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export function useInvalidateQueriesOnLanguageChange() { | ||
const { i18n } = useTranslation(); | ||
const languageRef = useRef(i18n.language); | ||
const queryClient = useQueryClient(); | ||
|
||
useEffect(() => { | ||
if (i18n.language === languageRef.current) { | ||
return; | ||
} | ||
|
||
// Evict everything from the cache but don't refetch anything. Queries will | ||
// be refetched when they become "enabled" when their screen gains focus. | ||
queryClient.invalidateQueries({ | ||
refetchType: 'none', | ||
}); | ||
}, [queryClient, i18n.language]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters