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:

Htmx Vs React

htmx vs. React: Choosing the right library for your project

Both htmx and React provide powerful tools for building web apps, but in different ways that are suited to different types of projects.

Temitope Oyedele
May 15, 2024 ⋅ 9 min read
Exploring The Top Pair Programming Tools

Exploring the top 5 pair programming tools

Review the top five pair programming tools, including how to use them, their features, drawbacks, pricing models, and more.

Elijah Asaolu
May 15, 2024 ⋅ 8 min read
Exploring Remix Vite And Other Breaking Changes In Version 2.2.0 And Version 2.7

Exploring Remix Vite support and other v2.20 and v7 changes

The Remix Vite integration helps speeds up development via features like HDR and HMR. Read about Remix Vite and other breaking changes.

Hussain Arif
May 14, 2024 ⋅ 7 min read
Caching In Next.js With Unstable_Cache

Caching in Next.js with unstable_cache

In this article, we explore the different caching strategies in Next.js, focusing on the `unstable_cache` function.

Kapeel Kokane
May 14, 2024 ⋅ 9 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