I have a header logo image for which alt and title attribute should render from i18n messages.
message_en.json
{
"logoTitle": "Link open in new tab or window",
"logoAlt": "some description goes here.."
}
header.js
import { FormattedMessage } from 'react-intl/dist';
<a
href={url}
title={<FormattedMessage id="logoTitle"/>}
>
<img
src={src}
alt={<FormattedMessage id='logoAlt' />}
/>
</a>
In the browser, alt and title renders as [Object][Object]
<a title="[object Object]">
<img id="masthead__logo__img" src="../assets/images/logo.png" alt="[object Object]">
</a>
How do I render FormattedMessage in this case?
FormattedMessage
is a React component that renders HTML. To render a plain string, useintl.formatMessage
function instead: