Skip to content

useObfuscatedEmail() ​

useObfuscatedEmail(rawEmail): object

Defined in: hooks/state/useObfuscatedEmail.ts:36

A React hook that safely obfuscates an email address to prevent spam bots from detecting it in the source HTML or static JavaScript.

The hook splits and reconstructs the email using JavaScript at runtime, so the full email will not appear in static markup or SSR output.

Parameters ​

rawEmail ​

string

The raw email address in the format [email protected]

Returns ​

object

An object containing:

  • href: A mailto: link that can be used in anchor tags
  • text: The full obfuscated email address for display

href ​

href: string | null

text ​

text: string | null

Examples ​

tsx
const { href, text } = useObfuscatedEmail('[email protected]')

return (
  <a href={href} title={text}>
    {text}
  </a>
)
tsx
const { text } = useObfuscatedEmail('[email protected]')

return (
  <span>{text}</span> // Text-only display (not clickable)
)

Released under the MIT License.