Install the Package
Install react-google-recaptcha using your preferred package manager:Peer Dependencies
The library requires React as a peer dependency. Make sure you have React installed in your project:Minimum React Version: react-google-recaptcha requires React >=16.4.1
Get Your reCAPTCHA Site Key
Before you can use reCAPTCHA in your application, you need to register your site with Google and obtain API keys.Visit the reCAPTCHA Admin Console
Go to http://www.google.com/recaptcha/admin and sign in with your Google account.
Register a New Site
Click the + button to register a new site:
- Label: A descriptive name for your site
- reCAPTCHA type: Select reCAPTCHA v2
- Choose your preferred challenge type:
- “I’m not a robot” Checkbox (most common)
- Invisible reCAPTCHA badge (programmatic)
Add Your Domains
Enter the domains where your application will be hosted:
- For development:
localhost - For production: Your actual domain (e.g.,
example.com)
Project Setup
Once you have your site key, you’re ready to integrate reCAPTCHA into your React application.Basic Setup
Import the component in your React file:Environment Variables (Recommended)
Store your site key in environment variables for better security and configuration management:.env
The environment variable prefix depends on your build tool:
- Create React App:
REACT_APP_ - Vite:
VITE_ - Next.js:
NEXT_PUBLIC_
Advanced Configuration
Using recaptcha.net
If google.com is blocked in your region, configure the library to use recaptcha.net instead:Google reCAPTCHA Enterprise
To use Google reCAPTCHA Enterprise instead of the free version:CSP Nonce Support
For applications with Content Security Policy (CSP), you can provide a nonce:Verification
You can verify your installation is working by checking if the component renders without errors. We’ll build a complete example in the next section.Next: Quick Start
Learn how to build your first reCAPTCHA-protected form with complete examples