zoukankan      html  css  js  c++  java
  • [React Intl] Use a react-intl Higher Order Component to format messages

    In some cases, you might need to pass a string from your intl messages.js file as a prop to a component. Instead of using react-intl components (which generate markup), we’ll use the injectIntl higher order component provided by react-intl. This will provide just the string we’re looking for, make the prop simpler, and avoid creating unnecessary DOM elements.

    We’ll also use props passed to the component from the Higher Order Component to clean up some redundant code.

     

    import React from 'react';
    import { injectIntl, FormattedMessage, FormattedHTMLMessage, FormattedRelative , FormattedTime, FormattedNumber } from 'react-intl';
    import {meanBy, round, sortBy} from 'lodash';
    
    import books from '../books.json';
    
    const BookDetail = ({match, intl}) => {
      
      return (
        <div className="BookDetail">
         ....
          <textarea placeholder={intl.formatMessage({
            id: 'detail.inputPlaceholder'
          })} cols="30" rows="10"></textarea>
        </div>
      )
    }
    
    export default injectIntl(BookDetail);
  • 相关阅读:
    HTTP报文语法/HTTP组成
    get和post的区别
    Jmeter图形结果
    Jmeter用表格查看结果
    Jmeter聚合报告
    Jmeter查看结果树
    Jmeter集合点
    Jmeter-BeanShell Sampler调用java代码
    Jmeter简单的接口测试
    get、post接口测试-java
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7265695.html
Copyright © 2011-2022 走看看