黑白梦黑白梦

toggle navtoggle nav
  • 文章
  • 专栏
  • 文章
  • 专栏

react-intl 国际化组件

发布于 2022-06-16, 更新于 2023-04-08

较为成熟,支持 hooks 使用。
https://www.npmjs.com/package/react-intl

npm install react-intl --save

hook:

const PostDate = ({date}) => {
  const intl = useIntl()
  return (
    <span title={intl.formatDate(date)}>
      <FormattedRelativeTime value={(Date.now() - date)/MS_IN_DAY} unit="day"/>
    </span>
  )
});

高阶组件,包裹:

export default connect(mapStateToProps,mapActionCreators)(injectIntl(App))

使用:

const {intl} = this.props;
let tmp = intl.formatMessage({id: 'intl.name'},{name: 'joe'});
本文收录于专栏

一些好用的 npm 前端开源库

收集一些好用的前端开源库,主要是 npm 包

©2015-2026 黑白梦 粤ICP备15018165号

联系: heibaimeng@foxmail.com