Files
30-seconds-of-code/snippets/Mailto.md
Isabelle Viktoria Maciohsek 26e071bb3f Update Mailto
2020-09-06 14:32:19 +03:00

666 B

title, tags
title tags
Mailto components,beginner

Renders a link formatted to send an email.

  • Destructure the component's props, use email, subject and body to create a <a> element with an appropriate href attribute.
  • Render the link with children as 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')
);