marsidev / react-turnstile

Cloudflare Turnstile integration for React.
https://www.npmjs.com/package/@marsidev/react-turnstile
MIT License
414 stars 25 forks source link

No callback on loading widget #45

Closed vsolovev closed 10 months ago

vsolovev commented 10 months ago

Feature Currently there is no way to detect when widget is ready to be executed, so explicit "execute" is kinda impossible. The ref.current became valid BEFORE widget loading is completed, thus "Turnstile not loaded" error occured during execution.

Wish to have extra callback when widget completed loading like it's done in another react-turnstile project (onLoad - called when the widget is loaded).

marsidev commented 10 months ago

I just exposed an onWidgetLoad callback that can be helpful for your use case. It runs when the widget loads or resets.

Please take note there are also:

Here is an example and comparison between the two packages: https://codesandbox.io/p/sandbox/loving-yalow-fhdpp2?file=%2Fsrc%2FApp.tsx

vsolovev commented 10 months ago

That's great, thank you!