@captchafox/react 1.0.0 → 1.0.1

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/dist/index.js CHANGED
@@ -76,7 +76,7 @@ var import_react = require("react");
76
76
  var import_jsx_runtime = require("react/jsx-runtime");
77
77
  var CaptchaFox = (0, import_react.forwardRef)(
78
78
  ({ sitekey, lng, mode, className, onError, onVerify, onLoad, onFail, onClose }, ref) => {
79
- const containerRef = (0, import_react.createRef)();
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,11 +116,11 @@ 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, {
123
+ const newWidgetId = yield (_c = window.captchafox) == null ? void 0 : _c.render(containerRef, {
124
124
  lng,
125
125
  sitekey,
126
126
  mode,
@@ -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, lng, 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
52
  ({ sitekey, lng, mode, className, onError, onVerify, onLoad, onFail, onClose }, ref) => {
53
- const containerRef = createRef();
53
+ const [containerRef, setContainerRef] = useState();
54
54
  const [widgetId, setWidgetId] = useState();
55
55
  const firstRendered = useRef(false);
56
56
  useImperativeHandle(
@@ -90,11 +90,11 @@ 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, {
97
+ const newWidgetId = yield (_c = window.captchafox) == null ? void 0 : _c.render(containerRef, {
98
98
  lng,
99
99
  sitekey,
100
100
  mode,
@@ -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, lng, 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.1",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",