666 B
666 B
title, tags
| title | tags |
|---|---|
| Mailto | components,beginner |
Renders a link formatted to send an email.
- Destructure the component's props, use
email,subjectandbodyto create a<a>element with an appropriatehrefattribute. - Render the link with
childrenas its content.
const Mailto = ({ email, subject, body, children }) => {
return (
<a href={`mailto:${email}?subject=${encodeURIComponent(subject) || ''}&body=${encodeURIComponent(body) || ''}`}>{children}</a>
);
};
ReactDOM.render(
<Mailto email="foo@bar.baz" subject="Hello & Welcome" body="Hello world!">
Mail me!
</Mailto>,
document.getElementById('root')
);