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

@captchaapi/react

v0.1.0

Published

React hook for captchaapi.eu proof of work CAPTCHA.

Downloads

31

Readme

@captchaapi/react

React hook for captchaapi.eu - EU-hosted, GDPR-compliant proof-of-work CAPTCHA. No cookies, no tracking, no Google.

Wraps the widget's programmatic window.captchaapi.solve() API with React state and unmount-safe abort handling. Built for controlled submit handlers in SPA setups such as Inertia, where the declarative data-captcha form attribute does not apply.

Why captchaapi.eu

  • EU-hosted (Hetzner Nuremberg) - GDPR-compliant by default, no data ever leaves the EU.
  • Proof-of-work - invisible to legitimate visitors, no friction puzzles to solve.
  • Server-side verification - your backend confirms each response with captchaapi.eu over a single call, secured by your secret key.

Requirements

  • React 18 or 19
  • The captcha.js widget loaded on the page (see below)

Installation

npm install @captchaapi/react

Load the widget once in your layout, before your app bundle:

<script>window.CAPTCHA_SITE_KEY = 'pk_live_...';</script>
<script src="https://captchaapi.eu/captcha.js" defer></script>

The site key is public and belongs in the browser. The secret key stays on your server and is only used to verify responses. Get both from the project dashboard.

If your site enforces a Content Security Policy, allow the widget and its API calls:

script-src https://captchaapi.eu;
connect-src https://captchaapi.eu;

Usage

Call solve() in your submit handler and send the resolved string to your backend as captchaapi_response:

import { useCaptcha } from '@captchaapi/react';

export default function ContactForm() {
    const { solve, solving, error } = useCaptcha();

    async function handleSubmit(event) {
        event.preventDefault();

        let response;
        try {
            response = await solve();
        } catch {
            return; // error state is set, render it below
        }

        // Add your framework's CSRF token here if the endpoint expects one
        // (Laravel: the X-XSRF-TOKEN header or a _token field).
        await fetch('/contact', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ captchaapi_response: response }),
        });
    }

    return (
        <form onSubmit={handleSubmit}>
            {error && <p>Verification failed ({error.code}), please try again.</p>}
            <button type="submit" disabled={solving}>Send</button>
        </form>
    );
}

With Inertia

Merge the response into the form payload via transform():

import { useForm } from '@inertiajs/react';
import { useCaptcha } from '@captchaapi/react';

export default function Newsletter() {
    const form = useForm({ email: '' });
    const { solve, solving } = useCaptcha();

    async function submit(event) {
        event.preventDefault();

        let response;
        try {
            response = await solve();
        } catch {
            return;
        }

        form
            .transform((data) => ({ ...data, captchaapi_response: response }))
            .post('/newsletter');
    }

    return (
        <form onSubmit={submit}>
            <input
                type="email"
                value={form.data.email}
                onChange={(event) => form.setData('email', event.target.value)}
            />
            {form.errors.captchaapi_response && <span>{form.errors.captchaapi_response}</span>}
            <button type="submit" disabled={form.processing || solving}>Subscribe</button>
        </form>
    );
}

On the Laravel side, validate the field with the captchaapi/laravel package and its ValidCaptcha rule. Validation failures land in form.errors like any other field, nothing Inertia-specific is needed on the server.

API

useCaptcha()

Returns an object with:

| Property | Type | Description | |---|---|---| | solve | () => Promise<string> | Runs one challenge and PoW cycle, resolves with the captchaapi_response value. Rejects with a CaptchaError. | | solving | boolean | True while a solve() call is in flight. | | error | CaptchaError \| null | Last error, cleared when the next solve() starts. |

Each resolved value verifies exactly once on the server. Never reuse it across submissions - call solve() again for every submit.

An in-flight solve() is aborted automatically when the component unmounts or when solve() is called again before the previous call settled.

The hook is SSR-safe: it only touches window inside solve(), which runs from event handlers, never during render.

CaptchaError

Extends Error with:

| Property | Type | Description | |---|---|---| | code | string | Widget error code, for example rate_limited, network_error, missing_site_key. widget_not_loaded means the captcha.js script tag is missing. | | retryAfter | number \| null | Seconds to wait when code is rate_limited, otherwise null. |

Testing your components

Mock the widget global in your test setup:

window.captchaapi = {
    solve: vi.fn().mockResolvedValue('token.12345'),
};

Security

See SECURITY.md for how to report vulnerabilities. This package never handles your secret key; verification always happens on your server.

License

MIT, see LICENSE.