i18next-hmr.ts 507 B

123456789101112131415161718192021222324
  1. import { useEffect } from "react"
  2. import { useTranslation } from "next-i18next"
  3. const isServer = typeof window === 'undefined';
  4. export const useI18nextHMR = (isDev: boolean) => {
  5. const { i18n } = useTranslation()
  6. if (!isDev) {
  7. return;
  8. }
  9. if (isServer) {
  10. import("i18next-hmr/server").then(({ applyServerHMR }) => {
  11. applyServerHMR(i18n)
  12. });
  13. }
  14. useEffect(() => {
  15. import("i18next-hmr/client").then(({ applyClientHMR }) => {
  16. applyClientHMR(i18n)
  17. })
  18. }, [i18n]);
  19. }