Skip to content

Instantly share code, notes, and snippets.

@jcunanan05
Created August 23, 2019 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcunanan05/231260134af4012ca533f5960297939f to your computer and use it in GitHub Desktop.
Save jcunanan05/231260134af4012ca533f5960297939f to your computer and use it in GitHub Desktop.
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" />
</IntlProvider>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment