[React Intl] Get locale value from intl injector

Get 'injectIntl' from  'react-intl', it is a high order componet.

We need to wrap our component into 'injectIntl':

import { injectIntl, FormattedMessage, FormattedHTMLMessage, FormattedRelative , FormattedTime, FormattedNumber } from 'react-intl';

....

export default injectIntl(BookDetail);

 

It will inject 'intl' prop into our component, we can get 'locale' out of it:

const BookDetail = ({match, intl}) => {
 const {locale} = intl;   
 ....
}

 

posted @ 2017-07-31 21:02  Zhentiw  阅读(277)  评论(0编辑  收藏  举报