<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: hkievet</title>
    <description>The latest articles on Forem by hkievet (@hkievet).</description>
    <link>https://forem.com/hkievet</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F149245%2F935c81cd-dedc-43d8-9af2-78389aa6ed59.jpeg</url>
      <title>Forem: hkievet</title>
      <link>https://forem.com/hkievet</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hkievet"/>
    <language>en</language>
    <item>
      <title>An easy way to hide an email from bots with react.</title>
      <dc:creator>hkievet</dc:creator>
      <pubDate>Thu, 07 Nov 2019 19:22:49 +0000</pubDate>
      <link>https://forem.com/hkievet/react-protecting-an-email-address-3cp0</link>
      <guid>https://forem.com/hkievet/react-protecting-an-email-address-3cp0</guid>
      <description>&lt;h1&gt;
  
  
  An easy way to hide an email from bots with react.
&lt;/h1&gt;

&lt;p&gt;I think that it's important to protect your email address from webcrawlers.&lt;/p&gt;

&lt;p&gt;Some companies use contact us forms, some freelance developers put the email address in the form of "contact me at foobar @ gmail dot com" or something like that.&lt;/p&gt;

&lt;p&gt;This is a fun way to retrieve an email address from a static react site by leveraging lazy loading. It's a pretty simple concept: lazy load a component containing the email address based on a trigger (in this case a button click).&lt;/p&gt;

&lt;p&gt;The code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as React from "react";

export interface IContactMeHrefProps {}

export const ContactMeHref: React.FC&amp;lt;IContactMeHrefProps&amp;gt; = props =&amp;gt; {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;a href="mailto:foobary@gmail.com"&amp;gt;
        foobar@gmail.com
      &amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default ContactMeHref;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as React from "react";
const ContactMeHref = React.lazy(() =&amp;gt; import("../resume/Contact"));

export interface IContactMeGateProps {}

// Make user click a button to show email adderss via lazy loading
export const ContactMeGate: React.FC&amp;lt;IContactMeGateProps&amp;gt; = props =&amp;gt; {
  const [showingEmail, setShowingEmail] = React.useState(false);

  let email = showingEmail ? (
    &amp;lt;ContactMeHref /&amp;gt;
  ) : (
    &amp;lt;button
      onClick={() =&amp;gt; setShowingEmail(true)}
    &amp;gt;
      Click for contact info
    &amp;lt;/button&amp;gt;
  );
  return (
    &amp;lt;React.Suspense fallback={&amp;lt;div&amp;gt;loading...&amp;lt;/div&amp;gt;}&amp;gt;
      &amp;lt;div&amp;gt;
        {email}
      &amp;lt;/div&amp;gt;
    &amp;lt;/React.Suspense&amp;gt;
  );
};

export default ContactMeGate;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can find an example of it on my website at &lt;a href="//hkievet.com"&gt;hkievet.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>lazyloading</category>
    </item>
  </channel>
</rss>
