Skip to content

react-i18next Translation Not Updating — Fix Language Switch

DodaTech Updated 2026-06-24 1 min read

In this fix, you'll learn why translations don't update after changeLanguage. This matters for multilingual app support, and appears in language switchers in internationalized apps.

The Problem

The following code demonstrates the typical mistake:

import i18n from './i18n';
function Greeting() {
  return <h1>{i18n.t('greeting')}</h1>;
}
// Doesn't update when language changes — no reactive binding

The Fix

Here is the corrected version:

import { useTranslation } from 'react-i18next';
function Greeting() {
  const { t, i18n } = useTranslation();
  return <h1>{t('greeting')}</h1>;
}
// Updates reactively when language changes

Prevention

  • Always use useTranslation hook in components that display translated text.
  • Call i18n.changeLanguage() to switch languages — it triggers re-renders.
  • Initialize i18n with react: { useSuspense: true } for Suspense integration.
  • Use Trans component for translations with embedded HTML or components.
  • Use t('key', { defaultValue: 'Fallback' }) for development without translation files.

Common Mistakes with i18n translation

  1. Using foldl instead of foldl' causing stack overflow on large lists
  2. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  3. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable

These mistakes appear frequently in real-world REACT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### How does useTranslation trigger re-renders?

useTranslation subscribes to i18n's languageChanged event. When changeLanguage is called, all useTranslation hooks receive it and call setState, triggering re-renders with new values.

What is the difference between useTranslation and withTranslation?

useTranslation is a hook (for functional components), withTranslation is an HOC (for class components). Both provide t and i18n. Prefer useTranslation.

Can I use t outside of React components?

Yes — import i18n directly and use i18n.t('key') in utility files. These won't react to language changes automatically.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro