# General Translation React SDKs (gt-react, gt-next): useMessages URL: https://generaltranslation.com/en-US/docs/react/reference/hooks/use-messages.mdx --- title: useMessages description: Resolve strings registered with msg into the active locale with General Translation gt-react. API reference for useMessages. --- The `useMessages` hook returns a function that resolves encoded strings created with [`msg`](/docs/react/reference/functions/msg) into the active locale. Use it to translate strings that were registered at module scope, outside a component. *Available in `gt-react`, `gt-next`, `gt-tanstack-start`, and `gt-react-native`. Examples import from `gt-react`; import from your framework's package instead.* ## Overview [#overview] Register a string with `msg`, then resolve it with the function `useMessages` returns. ```tsx const m = useMessages();
{m(encodedString)}
; ``` *Note: In `gt-react`, call `useMessages` under a [`{m(encodedGreeting)}
; } ``` ```tsx import { msg, useMessages } from 'gt-react'; const encodedGreeting = msg('Hello, {name}!'); export default function TranslateGreeting() { const m = useMessages(); return{m(encodedGreeting, { name: 'Bob' })}
; // "Hello, Bob!" } ``` ```tsx import { msg, useMessages } from 'gt-react'; // Variables passed to msg() take precedence over those passed to m() const encodedGreeting = msg('Hello, {name}!', { name: 'Alice' }); export default function TranslateGreeting() { const m = useMessages(); return{m(encodedGreeting, { name: 'Bob' })}
; // "Hello, Alice!" } ``` ## Notes [#notes] - `useMessages` resolves encoded strings from [`msg`](/docs/react/reference/functions/msg). - In an async App Router component, use [`getMessages`](/docs/react/nextjs/reference/functions/get-messages) instead. - Translations happen at build time (or on demand in development).