npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mecaptcha/verify-react

v0.2.1

Published

React components for MeCaptcha SMS verification

Readme

@mecaptcha/verify-react

React components for MeCaptcha SMS verification. Beautiful, accessible, and easy to integrate.

Installation

npm install @mecaptcha/verify-react
# or
pnpm add @mecaptcha/verify-react
# or
yarn add @mecaptcha/verify-react

Quick Start

import { MeCaptcha } from '@mecaptcha/verify-react';

function App() {
  return (
    <MeCaptcha
      apiKey="mec_live_..."
      onVerify={(result) => {
        console.log('Verified!', result.creditsAwarded);
      }}
    />
  );
}

Components

<MeCaptcha />

Standalone verification component with full UI flow.

Props:

  • apiKey (string, required) - Your MeCaptcha API key
  • onVerify (function, required) - Called when verification succeeds
  • onError (function, optional) - Called when errors occur
  • defaultCountryCode (string, optional) - Default country code (default: "+1")
  • theme (string, optional) - "light" | "dark" | "auto"
  • showBranding (boolean, optional) - Show MeCaptcha logo (default: true)
  • phoneNumber (string, optional) - External phone number (skips phone input, shows code input)
  • countryCode (string, optional) - Country code when using external phone number
  • baseUrl (string, optional) - Custom API base URL

Ref Methods (when using external phone number):

  • ref.current.sendCode() - Send verification code to the phone number
  • ref.current.verifyCode(code: string) - Verify a code manually

Example:

<MeCaptcha
  apiKey="mec_live_..."
  onVerify={(result) => {
    console.log('Credits:', result.creditsAwarded);
    console.log('Has account:', result.hasMeCaptcha);
  }}
  onError={(error) => {
    console.error('Error:', error.message);
  }}
  defaultCountryCode="+44"
/>

<MeCaptchaProtect />

Wrapper component that protects content until user is verified.

Props:

  • apiKey (string, required) - Your MeCaptcha API key
  • children (ReactNode, required) - Protected content
  • onVerified (function, optional) - Called when verification succeeds
  • requireReauth (number, optional) - Re-verify after X minutes
  • storageKey (string, optional) - Session storage key (default: "mecaptcha_verified")

Example:

<MeCaptchaProtect apiKey="mec_live_...">
  <ProtectedDashboard />
</MeCaptchaProtect>

Hooks

useMeCaptchaVerify(apiKey, options?)

Headless hook for building custom UIs.

Returns:

{
  phoneNumber: string;
  setPhoneNumber: (phone: string) => void;
  countryCode: string;
  setCountryCode: (code: string) => void;
  code: string;
  setCode: (code: string) => void;
  step: "phone" | "code";
  isLoading: boolean;
  error: string | null;
  hasMeCaptcha: boolean;
  isVerified: boolean;
  resendCooldown: number;
  sendCode: () => Promise<void>;
  verifyCode: (code?: string) => Promise<void>;
  checkPhone: (phone?: string) => Promise<boolean>;
  reset: () => void;
  editNumber: () => void;
  getFullPhoneNumber: () => string;
}

Example:

function CustomVerify() {
  const {
    phoneNumber,
    setPhoneNumber,
    sendCode,
    verifyCode,
    isLoading,
    error
  } = useMeCaptchaVerify('mec_live_...', {
    onVerify: (result) => console.log('Success!', result),
    onError: (error) => console.error('Error:', error),
  });

  return (
    <div>
      <input 
        value={phoneNumber}
        onChange={(e) => setPhoneNumber(e.target.value)}
      />
      <button onClick={sendCode}>Send Code</button>
    </div>
  );
}

useMeCaptchaRef(options?)

Hook to simplify using MeCaptcha with external phone number control. Provides validation helpers and convenient ref management.

Options:

  • phoneNumber (string, optional) - Phone number to validate
  • countryCode (string, optional) - Country code (default: "+1")

Returns:

{
  ref: RefObject<MeCaptchaHandle>;
  isValidPhone: boolean;
  sendCode: () => Promise<void>;
  fullPhoneNumber: string | null;
}

Example:

function MyComponent() {
  const [phoneNumber, setPhoneNumber] = useState('');
  
  const { ref, isValidPhone, sendCode } = useMeCaptchaRef({
    phoneNumber,
    countryCode: '+1'
  });

  return (
    <>
      <input
        value={phoneNumber}
        onChange={(e) => setPhoneNumber(e.target.value)}
      />
      <button onClick={sendCode} disabled={!isValidPhone}>
        Send Code
      </button>
      <MeCaptcha
        ref={ref}
        apiKey="mec_live_..."
        phoneNumber={phoneNumber}
        onVerify={handleVerify}
      />
    </>
  );
}

useMeCaptchaContext()

Access verification state within <MeCaptchaProtect>.

Returns:

{
  apiKey: string;
  isVerified: boolean;
  verificationResult?: VerifyCodeResult;
}

Example:

function ProtectedContent() {
  const { verificationResult } = useMeCaptchaContext();
  
  return (
    <div>
      <p>Credits earned: {verificationResult?.creditsAwarded}</p>
    </div>
  );
}

function App() {
  return (
    <MeCaptchaProtect apiKey="mec_live_...">
      <ProtectedContent />
    </MeCaptchaProtect>
  );
}

Styling

Components use inline styles with theme support. Colors adapt to system dark mode automatically.

Custom Theme (coming soon):

<MeCaptcha
  apiKey="mec_live_..."
  theme="dark"
  onVerify={handleVerify}
/>

Features

Phone Input - Country code selector + formatted input
Code Input - 6-digit input with auto-focus
Auto-submit - Submits when 6 digits entered
Paste Support - Paste 6-digit codes
Resend Logic - 60-second cooldown
Download Prompt - Shown for non-MeCaptcha users
Session Persistence - Survives page refresh
Dark Mode - Auto-detects system preference
Accessible - ARIA labels, keyboard navigation
Mobile Friendly - Responsive design
External Phone Control - Use your own phone input, MeCaptcha handles code verification
React 18 & 19 Support - Works with both versions

TypeScript

Full TypeScript support included:

import type { 
  MeCaptchaProps,
  MeCaptchaProtectProps,
  VerifyCodeResult 
} from '@mecaptcha/verify-react';

Examples

See the examples directory:

License

MIT