Files
30-seconds-of-code/snippets/Mailto.md
Angelos Chalaris ae78e6d456 Update tags for all snippets
Resolves #92
2020-03-16 12:50:44 +02:00

674 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 props.children as its content.
function Mailto({ email, subject, body, ...props }) {
  return (
    <a href={`mailto:${email}?subject=${encodeURIComponent(subject) || ''}&body=${encodeURIComponent(body) || ''}`}>{props.children}</a>
  );
}
ReactDOM.render(
  <Mailto email="foo@bar.baz" subject="Hello & Welcome" body="Hello world!">
    Mail me!
  </Mailto>,
  document.getElementById('root')
);