New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@hcaptcha/react-hcaptcha

Package Overview
Dependencies
Maintainers
3
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hcaptcha/react-hcaptcha - npm Package Compare versions

Comparing version 1.4.4 to 1.5.0

9

dist/esm/index.js

@@ -32,3 +32,4 @@ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";

script.src = domain + "/1/api.js?render=explicit&onload=" + HCAPTCHA_LOAD_FN_NAME;
script.async = true;
script.async = params.loadAsync !== undefined ? params.loadAsync : true;
delete params.loadAsync;

@@ -150,3 +151,4 @@ script.onerror = function (event) {

sentry = _this$props.sentry,
custom = _this$props.custom;
custom = _this$props.custom,
loadAsync = _this$props.loadAsync;
var mountParams = {

@@ -162,3 +164,4 @@ apihost: apihost,

sentry: sentry,
custom: custom
custom: custom,
loadAsync: loadAsync
};

@@ -165,0 +168,0 @@ mountCaptchaScript(mountParams).then(this.handleOnLoad)["catch"](this.handleError);

@@ -59,3 +59,4 @@ "use strict";

script.src = "".concat(domain, "/1/api.js?render=explicit&onload=").concat(HCAPTCHA_LOAD_FN_NAME);
script.async = true;
script.async = params.loadAsync !== undefined ? params.loadAsync : true;
delete params.loadAsync;

@@ -184,3 +185,4 @@ script.onerror = function (event) {

sentry = _this$props.sentry,
custom = _this$props.custom;
custom = _this$props.custom,
loadAsync = _this$props.loadAsync;
var mountParams = {

@@ -196,3 +198,4 @@ apihost: apihost,

sentry: sentry,
custom: custom
custom: custom,
loadAsync: loadAsync
};

@@ -199,0 +202,0 @@ mountCaptchaScript(mountParams).then(this.handleOnLoad)["catch"](this.handleError);

{
"name": "@hcaptcha/react-hcaptcha",
"version": "1.4.4",
"version": "1.5.0",
"types": "types/index.d.ts",
"type": "module",
"main": "dist/index.js",

@@ -14,3 +15,3 @@ "module": "dist/esm/index.js",

"scripts": {
"start": "webpack-dev-server --config ./webpack.config.js --mode development",
"start": "webpack serve",
"test": "jest",

@@ -41,3 +42,3 @@ "watch": "babel src -d dist --copy-files --watch",

"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.10",

@@ -47,2 +48,3 @@ "@babel/plugin-transform-runtime": "^7.14.5",

"@babel/preset-react": "^7.12.10",
"@jest/globals": "^29.5.0",
"@types/react": "^16.0.0",

@@ -52,10 +54,11 @@ "babel-loader": "^8.2.2",

"cross-env": "^7.0.3",
"html-webpack-plugin": "^3.2.0",
"jest": "^26.6.3",
"html-webpack-plugin": "^5.5.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"rimraf": "^3.0.2",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
"webpack": "^5.76.3",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.13.1"
},

@@ -62,0 +65,0 @@ "dependencies": {

# React hCaptcha Component Library
## Description
hCaptcha Component Library for ReactJS.
[hCaptcha](https://www.hcaptcha.com) is a drop-replacement for reCAPTCHA that protects user privacy, rewards websites, and helps companies get their data labeled.
[hCaptcha](https://www.hcaptcha.com) is a drop-replacement for reCAPTCHA that protects user privacy.
Sign up at [hCaptcha](https://www.hcaptcha.com) to get your sitekey today. **You need a sitekey to use this library.**
*Also compatible with Preact.*
1. [Installation](#installation)
2. [References](#references)
3. [Debugging](#debugging)
4. [Contributing](#contributing)
## Installation

@@ -19,7 +25,7 @@

### Usage
### Implementation
The two requirements for usage are the `sitekey` [prop](#props) and a `parent component` such as a `<form />`. The component will automatically include and load the
hCaptcha API library and append it to the parent component. This is designed for ease of use with the hCaptcha API!
#### Basic Usage
#### Standard

@@ -37,17 +43,3 @@ ```js

**A note about TypeScript usage:** If you want to reassign the component name, you could consider making a util that imports the component, then re-exports it as a default. Example:
```ts
// utils/captcha.ts
import HCaptcha from '@hcaptcha/react-hcaptcha';
export default HCaptcha;
// MyFormComponent.tsx
import { default as RenamedCaptcha } from '../utils/captcha';
<FormComponent>
<RenamedCaptcha sitekey="your-sitekey" />
</FormComponent>
```
#### Programmatic Usage
#### Programmatic
In the event you want to call the hCaptcha client API directly, you can do so by using the hook `useRef` and waiting for `onLoad` to be called. By waiting for `onLoad` the hCaptcha API will be ready and the hCaptcha client will have been setup. See the following example:

@@ -91,4 +83,19 @@

#### Advanced usage
**Typescript Support** \
If you want to reassign the component name, you could consider making a util that imports the component, then re-exports it as a default.
```ts
// utils/captcha.ts
import HCaptcha from '@hcaptcha/react-hcaptcha';
export default HCaptcha;
// MyFormComponent.tsx
import { default as RenamedCaptcha } from '../utils/captcha';
<FormComponent>
<RenamedCaptcha sitekey="your-sitekey" />
</FormComponent>
```
#### Advanced
In most real-world implementations, you'll probably be using a form library such as [Formik](https://github.com/jaredpalmer/formik) or [React Hook Form](https://github.com/react-hook-form/react-hook-form).

@@ -117,4 +124,5 @@

### References
### Props
#### Props

@@ -139,3 +147,3 @@ |Name|Values/Type|Required|Default|Description|

### Events
#### Events

@@ -152,3 +160,3 @@ |Event|Params|Description|

### Methods
#### Methods

@@ -164,3 +172,4 @@ |Method|Description|

**NOTE**: Make sure to reset the hCaptcha state when you submit your form by calling the method `.resetCaptcha` on your hCaptcha React Component! Passcodes are one-time use, so if your user submits the same passcode twice then it will be rejected by the server the second time.
> **Note** \
> Make sure to reset the hCaptcha state when you submit your form by calling the method `.resetCaptcha` on your hCaptcha React Component! Passcodes are one-time use, so if your user submits the same passcode twice then it will be rejected by the server the second time.

@@ -173,6 +182,21 @@ Please refer to the demo for examples of basic usage and an invisible hCaptcha.

### Debugging
1. #### Invalid hCaptcha Id: <hcaptcha_id>
This issue generally occurs when the component is re-rendered causing the current `useRef` to become stale, meaning the `ref` being used is no longer available in the DOM.
2. #### Make sure you don't double-import the api.js script
Importing the JS SDK twice can cause unpredictable behavior, so don't do a direct import separately if you are using react-hcaptcha.
3. #### Make sure you are using `reCaptchaCompat=false` if you have the reCAPTCHA JS loaded on the same page.
The hCaptcha "compatibility mode" will interfere with reCAPTCHA, as it adds properties with the same name. If for any reason you are running both hCaptcha and reCAPTCHA in parallel (we recommend only running hCaptcha) then please disable our compatibility mode.
---
### Contributing
### Note for maintainers
#### Scripts

@@ -199,6 +223,7 @@

`sudo echo "127.0.0.1 fakelocal.com" >> /private/etc/hosts`
```
sudo echo "127.0.0.1 fakelocal.com" >> /private/etc/hosts
npm start -- --disable-host-check
```
`npm start -- --disable-host-check`
open [http://fakelocal.com:9000](http://fakelocal.com:9000) to start the example.

@@ -31,3 +31,6 @@ import * as React from 'react';

script.src = `${domain}/1/api.js?render=explicit&onload=${HCAPTCHA_LOAD_FN_NAME}`;
script.async = true;
script.async = params.loadAsync !== undefined? params.loadAsync : true;
delete params.loadAsync;
script.onerror = (event) => rejectFn('script-error');

@@ -143,3 +146,4 @@

sentry,
custom
custom,
loadAsync
} = this.props;

@@ -156,3 +160,4 @@ const mountParams = {

sentry,
custom
custom,
loadAsync
};

@@ -329,3 +334,3 @@

const { elementId } = this.state;
return <div ref={this.ref} id={elementId}></div>
return <div ref={this.ref} id={elementId}></div>;
}

@@ -332,0 +337,0 @@ }

@@ -31,2 +31,3 @@ // Type definitions for @hcaptcha/react-hcaptcha 0.1

reCaptchaCompat?: boolean;
loadAsync?: boolean;
}

@@ -33,0 +34,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc