useObfuscatedEmail()
useObfuscatedEmail(
rawEmail
):object
Defined in: src/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
: Amailto:
link that can be used in anchor tagstext
: The full obfuscated email address for display
href
href:
null
|string
text
text:
null
|string
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)
)