-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
Hi there.
I made this library over 2.5 years ago when I wasn't deeply familiar with React and it shows in some design decisions (eg. userRef instead of ref because I couldn't figure out how to type it correctly).
Here's my ideas for v2:
- Use
refinstead ofuserRefand make it properly typed (breaking change)
export function FormCaptcha({ cdata }: { cdata: string }) {
const turnstile = useTurnstile();
const ref = useRef<HTMLDivElement>();
useEffect(() => {
turnstile.reset(ref);
}, []);
return (
<Turnstile sitekey="..." cData={cdata} action="login-form" ref={ref} />
)
}- Expand
useTurnstilehook to cover more use cases:
export function FormCaptcha({ cdata }: { cdata: string }) {
const turnstile = useTurnstile({
sitekey: "...",
cData: cdata,
action: "login-form"
});
useEffect(() => {
// this will work even with multiple instances of turnstile:
turnstile.reset()
}, []);
return (
<turnstile.Render />
)
}useTurnstile would either return a "BoundTurnstile" instance (with .Render component) if it's called with arguments or return the normal Turnstile API if not for backwards compatibility.
- remove "boundTurnstileObject" passed to callbacks (breaking change)
- internal: move away from
useStatehack and instead useuseRef - cleanup
onSuccess/onVerify(breaking change) - move
fixedSizeoption to its own component (breaking change)
export function FormCaptcha() {
const turnstile = useTurnstile({
sitekey: "...",
action: "login-form",
size: "compact"
});
return (
<turnstile.Container className="bg-blue">
<turnstile.Render />
</turnstile.Container>
)
}
export function FormCaptcha2() {
return (
<TurnstileContainer size="compact" className="bg-blue">
<Turnstile />
</TurnstileContainer>
)
}- either automatically detect if we are being SSR'ed and thrown an error or detect it and only render on the client-side (might be breaking)
- add a "TurnstileProvider" or similar which lets you preload the external Turnstile api.js
EgonThornejosheche, archisvaze, danielb7390 and 9uifranco
Metadata
Metadata
Assignees
Labels
No labels