How do you pass a parameter to defineMessages in react-intl?
If I understood you correctly like this:
const messages = defineMessages({
dataError: {
id: 'data.error',
defaultMessage: 'Could not retrieve data: {message}'
}
})
<FormattedMessage
{...messages.dataError}
values={{message: `Could not retrieve data: ${e}`}}
/>
need to replace [default message]
with {e}
in defineMessages
const messages = defineMessages({
dataError: {
id: 'data.error',
defaultMessage: 'Could not retrieve data: {e}'
}
})
Define Message variable
const message = "Error Message";
Pass message variable in Formatted Message
<FormattedMessage
{...messages.dataError}
values={{ e: `${message}` }}
/>
Out Put in below
<span>Could not retrieve data: Error Message</span>
Hope it will help you.