File tree Expand file tree Collapse file tree 3 files changed +7
-1
lines changed Expand file tree Collapse file tree 3 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212- Support for the new ` onTimeout ` callback
1313- ` autoResetOnExpire ` for automatically resetting the Turnstile widget once the token expires
1414- ` retry ` & ` retryInterval `
15+ - custom ` ref ` argument for using your own ref (#7 )
1516
1617## [ 1.0.5] - 2022-10-22
1718
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ Turnstile takes the following arguments:
4545| retryInterval | number | interval of retries in ms |
4646| autoResetOnExpire | boolean | automatically reset the widget when the token expires |
4747| id | string | id of the div |
48+ | ref | Ref | custom react ref for the div |
4849| className | string | passed to the div |
4950| style | object | passed to the div |
5051
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ let ensureTurnstile: () => Promise<any>;
4343
4444export default function Turnstile ( {
4545 id,
46+ ref : userRef ,
4647 className,
4748 style,
4849 sitekey,
@@ -62,9 +63,11 @@ export default function Turnstile({
6263 onExpire,
6364 onTimeout,
6465} : TurnstileProps ) {
65- const ref = useRef < HTMLDivElement | null > ( null ) ;
66+ const ownRef = useRef < HTMLDivElement | null > ( null ) ;
6667 const inplaceState = useState < TurnstileCallbacks > ( { onVerify } ) [ 0 ] ;
6768
69+ const ref = userRef ?? ownRef ;
70+
6871 useEffect ( ( ) => {
6972 if ( ! ref . current ) return ;
7073 let cancelled = false ;
@@ -144,6 +147,7 @@ interface TurnstileProps extends TurnstileCallbacks {
144147 autoResetOnExpire ?: boolean ;
145148
146149 id ?: string ;
150+ ref ?: React . MutableRefObject < HTMLDivElement > ;
147151 className ?: string ;
148152 style ?: React . CSSProperties ;
149153}
You can’t perform that action at this time.
0 commit comments