How to retrieve a string in ReactIntl 2.0 without using FormattedMessage

前端 未结 4 2006
南笙
南笙 2021-01-02 03:29

Please correct me if I am wrong, FormattedMessage in ReactIntl returns a string wrapped by span tags. In ReactIntl 1.2, we have the option to use this.getIntlMessage(\

4条回答
  •  天涯浪人
    2021-01-02 04:15

    You can easily return string using intl object provided by react-intl.

    this is how you use intl object inside react class in much more easier way.

    note: Render Component (main component) should wrap with IntlProvider

    class MySubComponent extends React.Component{
      {/*....*/}
    
      render(){
        return(
         
    ) } } MySubComponent.contextTypes ={ intl:React.PropTypes.object.isRequired }

    By defining contextTypes it will enable you to use intl object which is a context type prop. See react context for more details.

提交回复
热议问题