in React JS by
Q:

How to use <FormattedMessage> as placeholder using React Intl?

1 Answer

0 votes
by

The <Formatted... /> components from react-intl return elements, not plain text, so they can't be used for placeholders, alt text, etc. In that case, you should use lower level API formatMessage(). You can inject the intl object into your component using injectIntl() higher-order component and then format the message using formatMessage() available on that object.

import React from 'react'
import { injectIntl, intlShape } from 'react-intl'

const MyComponent = ({ intl }) => {
  const placeholder = intl.formatMessage({id: 'messageId'})
  return <input placeholder={placeholder} />
}

MyComponent.propTypes = {
  intl: intlShape.isRequired
}

export default injectIntl(MyComponent)
Click here to read more about React JS
Click here to read more about Insurance

Related questions

0 votes
asked Mar 3, 2020 in React JS by miceperry
0 votes
asked Mar 4, 2020 in React JS by JackTerrance
0 votes
0 votes
asked Jul 2, 2019 in React JS by Venkatshastri
0 votes
asked Mar 2, 2020 in React JS by RShastri
0 votes
asked Mar 1, 2020 in React JS by RShastri
0 votes
...