recaptcha-react-hook
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

react-recaptcha-hook

React hook for google-recaptcha v3

Install

// with npm
npm install react-recaptcha-hook
 
// with yarn
yarn add react-recaptcha-hook

How to use

import React, { useEffect } from 'react';
import useRecaptcha, { Badge } from 'react-recaptcha-hook';
 
const RecaptchaComponent = ({ action, sitekey, onToken }) => {
  const execute = useRecaptcha({ sitekey, hideDefaultBadge: true });
 
  useEffect(() => {
    const getToken = async () => {
      const token = await execute(action);
      onToken(token);
    };
 
    getToken();
  }, []);
 
  return <Badge />;
};
 
export default RecaptchaComponent;

Server side validation

License

MIT

Package Sidebar

Install

npm i recaptcha-react-hook

Weekly Downloads

0

Version

1.0.8

License

MIT

Unpacked Size

12.2 kB

Total Files

12

Last publish

Collaborators

  • stephenway