React-Intl How to use FormattedMessage in input placeholder

前端 未结 11 604
走了就别回头了
走了就别回头了 2020-12-13 03:20

I\'m unsure how to get the values from


into a placeholder format like input:<

11条回答
  •  囚心锁ツ
    2020-12-13 04:19

    As from React version >= 16.8, you can use useIntl hook :

    import React from 'react';
    import { IntlProvider, useIntl } from 'react-intl';
    
    const FunctionComponent = () => {
        const intl = useIntl();
        const lang = "en";
        const messages = {
          en: {
            'placeholderMessageId': 'placeholder in english',
          },
          fr: {
            'placeholderMessageId': 'placeholder en fançais',
          }
        }
        return ( 
          
               
          
          );
        };
    
    export default FunctionComponent;
    

提交回复
热议问题