You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP →

captcha-generator-react

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

captcha-generator-react - npm Package Compare versions

Comparing version

to
1.6.7

{
"name": "captcha-generator-react",
"version": "1.6.6",
"version": "1.6.7",
"main": "index.mjs",

@@ -5,0 +5,0 @@ "types": "index.d.ts",

@@ -26,3 +26,3 @@ # Generate captcha

# Usage
# Usage in plain React.

@@ -51,4 +51,7 @@ ```js

e.preventDefault();
console.log();
console.log(captchaText === captcha);
if (captchaText === captcha) {
alert("success");
} else {
alert("fail");
}
}}

@@ -72,2 +75,50 @@ >

# Usage in Nextjs server components (v13 and up).
```js
"use client";
import generateCaptcha from "generate-captcha";
import { useEffect, useState } from "react";
function CaptchaGenerator() {
const [captcha, setCaptcha] = useState("");
const [captchaText, setCaptchaText] = useState("");
const [captchaImage, setCaptchaImage] = useState(null);
useEffect(() => {
const { text, imgUrl } = generateCaptcha();
setCaptchaText(text);
setCaptchaImage(imgUrl);
}, []);
return (
<>
<img src={captchaImage || undefined} alt="" className="mb" />
<form
onSubmit={(e) => {
e.preventDefault();
if (captchaText === captcha) {
alert("success");
} else {
alert("fail");
}
}}
>
<input
type="text"
name="captcha"
onChange={(e) => {
setCaptcha(e.target.value);
}}
/>
<button>Submit</button>
</form>
</>
);
}
export default CaptchaGenerator;
```
# Customize

@@ -74,0 +125,0 @@