2022-06-09
3167
#react
David Omotayo
115071
Jun 9, 2022 ⋅ 11 min read

How to implement reCAPTCHA in a React application

David Omotayo Frontend developer and indie game enthusiast.

Recent posts:

Styling HTML Details and Summary With Modern CSS

Styling HTML <details> and <summary> with modern CSS

Use CSS to style and manage disclosure widgets, which are the HTML `details` and `summary` elements.

Rob O'Leary
Dec 26, 2024 ⋅ 11 min read
react native's new architecture: sync and async rendering

React Native’s New Architecture: Sync and async rendering

React Native’s New Architecture offers significant performance advantages. In this article, you’ll explore synchronous and asynchronous rendering in React Native through practical use cases.

Emmanuel John
Dec 24, 2024 ⋅ 8 min read
Building a Full-Featured Laravel Admin Dashboard with Filament

Building a full-featured Laravel admin dashboard with Filament

Build scalable admin dashboards with Filament and Laravel using Form Builder, Notifications, and Actions for clean, interactive panels.

Kayode Adeniyi
Dec 20, 2024 ⋅ 5 min read
Working With URLs In JavaScript

Working with URLs in JavaScript

Break down the parts of a URL and explore APIs for working with them in JavaScript, parsing them, building query strings, checking their validity, etc.

Joe Attardi
Dec 19, 2024 ⋅ 6 min read
View all posts

13 Replies to "How to implement reCAPTCHA in a React application"

  1. Great post. I ran into some trouble after naming my component in lower case and React wasnt reconizing it as a component until i changed it lo upper case.

  2. Thank you, Mark. React components always start with uppercase letters. The library treats any component with lowercase initials as HTML elements.

    1. Hi Rasam, you have to perform a conditional check based on the response you get from the server. If it’s positive, submit the form. If not, do otherwise. I hope this helps.

      1. Something’s wrong with the backend here – the form does not verify the secret key or token and always shows that its human – regardless if you click the checkbox or not

        1. Hi Laura, I would like to express my apologies for any inconvenience you may have experienced. The handling of the Google API response was not executed correctly. However, I have rectified the issue and I hope you can continue with your work without any further issues. happy hacking!

  3. Using nodejs for the captcha verification process is totally unnecessary.
    Just use const [isVerified, setVerified] = useState(false);

    And create an onChange handler and add it to your recaptcha component
    All the onChange handler has to do is check for a token and if there is a token set “isVerified” to true

    1. This approach of yours only checks for a token. Node.js is for verifying the generated token with Google’s API.

  4. Does anyone know how the ‘reaptcha’ library works? I’ve looked through their example code but I can’t see where they’re verifying the captcha with Google’s servers.

    And if they are handling verification with Google, how are they doing it without the secret key? AFAIK and according to this article, it’s essential to the verification process.

  5. Thanks for this tutorial. It seems that this tutorial has some errors:
    – For the server, the `npm i` command should also include `cors` (besides `express`, `axios`, `dotenv`)
    – In the updated `handleSubmit` function that makes the request to the server, the `axios.post` call should take the arguments `(“http://localhost:2000/post”, { inputVal, token })`, instead of `(inputVal, token)`

Leave a Reply