@captchafox/react 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,13 +33,13 @@ function Example() {
33
33
  | **Prop** | **Type** | **Description** | **Required** |
34
34
  | -------- | ----------------------- | ------------------------------------------------------------------------------- | ------------ |
35
35
  | sitekey | `string` | The sitekey for the widget | ✅ |
36
- | lng | `string` | The language the widget should display. Defaults to automatically detecting it. | |
37
- | mode | `inline\|popup\|hidden` | The mode the widget should be displayed in | |
38
- | onVerify | `function` | Called with the response token after successful verification | |
39
- | onFail | `function` | Called after unsuccessful verification | |
40
- | onError | `function` | Called if an error occured | |
41
- | onExpire | `function` | Called if the challenge expired | |
42
- | onClose | `function` | Called if the challenge was closed | |
36
+ | lang | `string` | The language the widget should display. Defaults to automatically detecting it. | |
37
+ | mode | `inline\|popup\|hidden` | The mode the widget should be displayed in . | |
38
+ | onVerify | `function` | Called with the response token after successful verification. | |
39
+ | onFail | `function` | Called after unsuccessful verification. | |
40
+ | onError | `function` | Called when an error occured. | |
41
+ | onExpire | `function` | Called when the challenge expires. | |
42
+ | onClose | `function` | Called when the challenge was closed. | |
43
43
 
44
44
  ### Using the verification callback
45
45
 
package/dist/index.js CHANGED
@@ -75,8 +75,8 @@ var isApiReady = () => typeof (window == null ? void 0 : window.captchafox) !==
75
75
  var import_react = require("react");
76
76
  var import_jsx_runtime = require("react/jsx-runtime");
77
77
  var CaptchaFox = (0, import_react.forwardRef)(
78
- ({ sitekey, lng, mode, className, onError, onVerify, onLoad, onFail, onClose }, ref) => {
79
- const containerRef = (0, import_react.createRef)();
78
+ ({ sitekey, lang, mode, className, onError, onVerify, onLoad, onFail, onClose }, ref) => {
79
+ const [containerRef, setContainerRef] = (0, import_react.useState)();
80
80
  const [widgetId, setWidgetId] = (0, import_react.useState)();
81
81
  const firstRendered = (0, import_react.useRef)(false);
82
82
  (0, import_react.useImperativeHandle)(
@@ -116,12 +116,12 @@ var CaptchaFox = (0, import_react.forwardRef)(
116
116
  [widgetId]
117
117
  );
118
118
  const renderCaptcha = () => __async(void 0, null, function* () {
119
- var _a, _b, _c, _d;
119
+ var _a, _b, _c;
120
120
  (_a = window.captchafox) == null ? void 0 : _a.remove(widgetId);
121
- if (!containerRef.current || ((_c = (_b = containerRef.current) == null ? void 0 : _b.children) == null ? void 0 : _c.length) === 1)
121
+ if (!containerRef || ((_b = containerRef == null ? void 0 : containerRef.children) == null ? void 0 : _b.length) === 1)
122
122
  return;
123
- const newWidgetId = yield (_d = window.captchafox) == null ? void 0 : _d.render(containerRef.current, {
124
- lng,
123
+ const newWidgetId = yield (_c = window.captchafox) == null ? void 0 : _c.render(containerRef, {
124
+ lang,
125
125
  sitekey,
126
126
  mode,
127
127
  onError,
@@ -133,6 +133,8 @@ var CaptchaFox = (0, import_react.forwardRef)(
133
133
  onLoad == null ? void 0 : onLoad();
134
134
  });
135
135
  (0, import_react.useEffect)(() => {
136
+ if (!containerRef)
137
+ return;
136
138
  if (firstRendered.current) {
137
139
  if (isApiReady()) {
138
140
  renderCaptcha();
@@ -148,8 +150,8 @@ var CaptchaFox = (0, import_react.forwardRef)(
148
150
  console.error("[CaptchaFox] Could not load script:", err);
149
151
  });
150
152
  }
151
- }, [sitekey, lng, mode]);
152
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: containerRef, id: widgetId, className });
153
+ }, [containerRef, sitekey, lang, mode]);
154
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: setContainerRef, id: widgetId, className });
153
155
  }
154
156
  );
155
157
  CaptchaFox.displayName = "CaptchaFox";
package/dist/index.mjs CHANGED
@@ -46,11 +46,11 @@ function loadCaptchaScript() {
46
46
  var isApiReady = () => typeof (window == null ? void 0 : window.captchafox) !== "undefined";
47
47
 
48
48
  // src/CaptchaFox.tsx
49
- import { createRef, forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
49
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
50
50
  import { jsx } from "react/jsx-runtime";
51
51
  var CaptchaFox = forwardRef(
52
- ({ sitekey, lng, mode, className, onError, onVerify, onLoad, onFail, onClose }, ref) => {
53
- const containerRef = createRef();
52
+ ({ sitekey, lang, mode, className, onError, onVerify, onLoad, onFail, onClose }, ref) => {
53
+ const [containerRef, setContainerRef] = useState();
54
54
  const [widgetId, setWidgetId] = useState();
55
55
  const firstRendered = useRef(false);
56
56
  useImperativeHandle(
@@ -90,12 +90,12 @@ var CaptchaFox = forwardRef(
90
90
  [widgetId]
91
91
  );
92
92
  const renderCaptcha = () => __async(void 0, null, function* () {
93
- var _a, _b, _c, _d;
93
+ var _a, _b, _c;
94
94
  (_a = window.captchafox) == null ? void 0 : _a.remove(widgetId);
95
- if (!containerRef.current || ((_c = (_b = containerRef.current) == null ? void 0 : _b.children) == null ? void 0 : _c.length) === 1)
95
+ if (!containerRef || ((_b = containerRef == null ? void 0 : containerRef.children) == null ? void 0 : _b.length) === 1)
96
96
  return;
97
- const newWidgetId = yield (_d = window.captchafox) == null ? void 0 : _d.render(containerRef.current, {
98
- lng,
97
+ const newWidgetId = yield (_c = window.captchafox) == null ? void 0 : _c.render(containerRef, {
98
+ lang,
99
99
  sitekey,
100
100
  mode,
101
101
  onError,
@@ -107,6 +107,8 @@ var CaptchaFox = forwardRef(
107
107
  onLoad == null ? void 0 : onLoad();
108
108
  });
109
109
  useEffect(() => {
110
+ if (!containerRef)
111
+ return;
110
112
  if (firstRendered.current) {
111
113
  if (isApiReady()) {
112
114
  renderCaptcha();
@@ -122,8 +124,8 @@ var CaptchaFox = forwardRef(
122
124
  console.error("[CaptchaFox] Could not load script:", err);
123
125
  });
124
126
  }
125
- }, [sitekey, lng, mode]);
126
- return /* @__PURE__ */ jsx("div", { ref: containerRef, id: widgetId, className });
127
+ }, [containerRef, sitekey, lang, mode]);
128
+ return /* @__PURE__ */ jsx("div", { ref: setContainerRef, id: widgetId, className });
127
129
  }
128
130
  );
129
131
  CaptchaFox.displayName = "CaptchaFox";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@captchafox/react",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",