@hcaptcha/react-hcaptcha 0.3.8 → 0.3.9

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
@@ -170,7 +170,7 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
170
170
  }
171
171
  }, {
172
172
  key: "renderCaptcha",
173
- value: function renderCaptcha() {
173
+ value: function renderCaptcha(onReady) {
174
174
  var isApiReady = this.state.isApiReady;
175
175
  if (!isApiReady) return; //Render hCaptcha widget and provide necessary callbacks - hCaptcha
176
176
 
@@ -182,6 +182,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
182
182
  this.setState({
183
183
  isRemoved: false,
184
184
  captchaId: captchaId
185
+ }, function () {
186
+ onReady && onReady();
185
187
  });
186
188
  }
187
189
  }, {
@@ -218,11 +220,12 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
218
220
  this.setState({
219
221
  isApiReady: true
220
222
  }, function () {
221
- // trigger onLoad if it exists
222
- var onLoad = _this3.props.onLoad;
223
- if (onLoad) onLoad(); // render captcha
224
-
225
- _this3.renderCaptcha();
223
+ // render captcha and wait for captcha id
224
+ _this3.renderCaptcha(function () {
225
+ // trigger onLoad if it exists
226
+ var onLoad = _this3.props.onLoad;
227
+ if (onLoad) onLoad();
228
+ });
226
229
  });
227
230
  }
228
231
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hcaptcha/react-hcaptcha",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "types": "types/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "files": [
package/src/index.js CHANGED
@@ -119,7 +119,7 @@ class HCaptcha extends React.Component {
119
119
  }
120
120
  }
121
121
 
122
- renderCaptcha() {
122
+ renderCaptcha(onReady) {
123
123
  const { isApiReady } = this.state;
124
124
  if (!isApiReady) return;
125
125
 
@@ -132,7 +132,9 @@ class HCaptcha extends React.Component {
132
132
  "callback" : this.handleSubmit,
133
133
  });
134
134
 
135
- this.setState({ isRemoved: false, captchaId });
135
+ this.setState({ isRemoved: false, captchaId }, () => {
136
+ onReady && onReady();
137
+ });
136
138
  }
137
139
 
138
140
  resetCaptcha() {
@@ -156,12 +158,13 @@ class HCaptcha extends React.Component {
156
158
 
157
159
  handleOnLoad () {
158
160
  this.setState({ isApiReady: true }, () => {
159
- // trigger onLoad if it exists
160
- const { onLoad } = this.props;
161
- if (onLoad) onLoad();
162
161
 
163
- // render captcha
164
- this.renderCaptcha();
162
+ // render captcha and wait for captcha id
163
+ this.renderCaptcha(() => {
164
+ // trigger onLoad if it exists
165
+ const { onLoad } = this.props;
166
+ if (onLoad) onLoad();
167
+ });
165
168
  });
166
169
  }
167
170