marsidev / react-turnstile

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

Is it possible to tell if the captcha is visible? #57

Closed sketchbuch closed 5 months ago

sketchbuch commented 8 months ago

I want to add a spacing between it and some buttons, but only when it is visible

marsidev commented 7 months ago

You can use the onBeforeInteractive callback, which runs before the challenge becomes interactive.

Example:

import { Turnstile } from '@marsidev/react-turnstile'
import React from 'react'

export default function Page() {
  const [isVisible, setIsVisible] = React.useState(false)

  return (
    <React.Fragment>
      <Turnstile
        siteKey="3x00000000000000000000FF"
        onBeforeInteractive={() => setIsVisible(true)}
      />

      {isVisible && <button>Conditional Button</button>}
    </React.Fragment>
  )
}
sketchbuch commented 7 months ago

yeah, but I want to know if it is visible. After onAfterInteractive fires it can still be visible. Because of this, when onBeforeInteractive fires it xcan already be visible.

marsidev commented 5 months ago

We don't have a onVisible callback, but we you can use the ResizeObserver API to achive what you need. Check this demo.