Files
30-seconds-of-code/snippets/Mailto.md
Mahf 2f79031e0e Revert "Merge pull request #1 from 30-seconds/master"
This reverts commit 285b5b9623, reversing
changes made to b9382db30b.
2019-02-06 13:09:02 +00:00

645 B

Mailto

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=${subject || ""}&body=${body || ""}`}>
      {props.children}
    </a>
  );
}
ReactDOM.render(
  <Mailto email="foo@bar.baz" subject="Hello" body="Hello world!">
    Mail me!
  </Mailto>,
  document.getElementById("root")
);