Created
August 23, 2019 01:42
-
-
Save jcunanan05/231260134af4012ca533f5960297939f to your computer and use it in GitHub Desktop.
react-intl sample code using messages for locale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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