Email link
Renders a link formatted to send an email (mailto: link).
- Use the
email,subjectandbodyprops to create a<a>element with an appropriatehrefattribute. - Use
encodeURIcomponentto safely encode thesubjectandbodyinto the link URL. - Render the link with
childrenas its content.
const Mailto = ({ email, subject = '', body = '', children }) => {
let params = subject || body ? '?' : '';
if (subject) params += `subject=${encodeURIComponent(subject)}`;
if (body) params += `${subject ? '&' : ''}body=${encodeURIComponent(body)}`;
return <a href={`mailto:${email}${params}`}>{children}</a>;
};