-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update with-react-intl example (#4825)
Changes: - added withIntl HOC because injectIntl do no hoist static methods - fixed `Cannot read property 'locale' of undefined`
- Loading branch information
1 parent
b122296
commit e2b5185
Showing
5 changed files
with
43 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import hoistNonReactStatics from 'hoist-non-react-statics' | ||
import { injectIntl } from 'react-intl' | ||
|
||
export const hoistStatics = (higherOrderComponent) => (BaseComponent) => { | ||
const NewComponent = higherOrderComponent(BaseComponent) | ||
hoistNonReactStatics(NewComponent, BaseComponent) | ||
|
||
return NewComponent | ||
} | ||
|
||
export default hoistStatics(injectIntl) |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,38 @@ | ||
import React from 'react' | ||
import {FormattedMessage, FormattedNumber, defineMessages, injectIntl} from 'react-intl' | ||
import React, { Component } from 'react' | ||
import { FormattedMessage, FormattedNumber, defineMessages } from 'react-intl' | ||
import Head from 'next/head' | ||
import Layout from '../components/Layout' | ||
import withIntl from '../lib/withIntl' | ||
|
||
const {description} = defineMessages({ | ||
const { description } = defineMessages({ | ||
description: { | ||
id: 'description', | ||
defaultMessage: 'An example app integrating React Intl with Next.js' | ||
} | ||
}) | ||
|
||
export default injectIntl(({intl}) => ( | ||
<Layout> | ||
<Head> | ||
<meta name='description' content={intl.formatMessage(description)} /> | ||
</Head> | ||
<p> | ||
<FormattedMessage id='greeting' defaultMessage='Hello, World!' /> | ||
</p> | ||
<p> | ||
<FormattedNumber value={1000} /> | ||
</p> | ||
</Layout> | ||
)) | ||
class Index extends Component { | ||
static getInitialProps () { | ||
// Do something | ||
} | ||
|
||
render () { | ||
const { intl } = this.props | ||
|
||
return ( | ||
<Layout> | ||
<Head> | ||
<meta name='description' content={intl.formatMessage(description)} /> | ||
</Head> | ||
<p> | ||
<FormattedMessage id='greeting' defaultMessage='Hello, World!' /> | ||
</p> | ||
<p> | ||
<FormattedNumber value={1000} /> | ||
</p> | ||
</Layout> | ||
) | ||
} | ||
} | ||
|
||
export default withIntl(Index) |