Skip to content

Commit

Permalink
Update with-react-intl example (#9180)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwang authored and timneutkens committed Oct 26, 2019
1 parent 2fcff3d commit 94e81c0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions examples/with-react-intl/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import App from 'next/app'
import React from 'react'
import { IntlProvider } from 'react-intl'
import { createIntl, createIntlCache, RawIntlProvider } from 'react-intl'

// This is optional but highly recommended
// since it prevents memory leak
const cache = createIntlCache()

export default class MyApp extends App {
static async getInitialProps ({ Component, router, ctx }) {
static async getInitialProps ({ Component, ctx }) {
let pageProps = {}

if (Component.getInitialProps) {
Expand All @@ -21,10 +25,18 @@ export default class MyApp extends App {
render () {
const { Component, pageProps, locale, messages } = this.props

const intl = createIntl(
{
locale,
messages
},
cache
)

return (
<IntlProvider locale={locale} messages={messages}>
<RawIntlProvider value={intl}>
<Component {...pageProps} />
</IntlProvider>
</RawIntlProvider>
)
}
}

0 comments on commit 94e81c0

Please sign in to comment.