Menu

gitpiper

Mailto react Code Snippet in 2022

componentsbeginner

Last Updated: 28 December 2022

Renders a link formatted to send an email (mailto: link).

  • Use the email, subject and body props to create a <a> element with an appropriate href attribute.
  • Use encodeURIcomponent to safely encode the subject and body into the link URL.
  • Render the link with children as 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>; };
ReactDOM.render( <Mailto email="foo@bar.baz" subject="Hello & Welcome" body="Hello world!"> Mail me! </Mailto>, document.getElementById('root') );

react snippet similar to Mailto For You in December 2022

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2022 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️