Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
react-intl sample code using messages for locale
import React, { useState } from "react";
import { IntlProvider, FormattedMessage } from "react-intl";
const messages = {
en: {
"app.hello": "Hello"
fr: {
"app.hello": "Bonjour"
function App() {
const [locale, setLocale] = useState("en");
return (
<IntlProvider locale={locale} messages={messages[locale]}>
<button onClick={() => setLocale("en")}>en</button>
<button onClick={() => setLocale("fr")}>fr</button>
<FormattedMessage id="app.hello" />
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment