Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lib/src/component/HCaptcha.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { flushSync } from 'react-dom';
import { hCaptchaLoader } from '@hcaptcha/loader';

import { getFrame, getMountElement } from '../utils.js';
Expand Down Expand Up @@ -252,20 +253,21 @@ export class HCaptcha extends React.Component {
}

handleOnLoad () {
this.setState({ isApiReady: true }, () => {
const element = getMountElement(this.props.scriptLocation);
const frame = getFrame(element);
const element = getMountElement(this.props.scriptLocation);
const frame = getFrame(element);

this._hcaptcha = frame.window.hcaptcha;
this._hcaptcha = frame.window.hcaptcha;

flushSync(() => {
this.setState({ isApiReady: true });
});

// render captcha and wait for captcha id
this.renderCaptcha(() => {
// trigger onLoad if it exists
// render captcha and wait for captcha id
this.renderCaptcha(() => {
// trigger onLoad if it exists

const { onLoad } = this.props;
if (onLoad) onLoad();
});
const { onLoad } = this.props;
if (onLoad) onLoad();
});
}

Expand Down
Loading