File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import * as React from 'react';
2
2
import * as ReactDom from 'react-dom' ;
3
3
import { GoogleReCaptchaProvider } from '../src/google-recaptcha-provider' ;
4
4
import { GoogleRecaptchaExample } from './google-recaptcha-example' ;
5
+ import { WithGoogleRecaptchaExample } from './with-google-recaptcha-example' ;
5
6
6
7
ReactDom . render (
7
8
< GoogleReCaptchaProvider
@@ -11,6 +12,7 @@ ReactDom.render(
11
12
>
12
13
< h2 > Google Recaptcha Example</ h2 >
13
14
< GoogleRecaptchaExample />
15
+ < WithGoogleRecaptchaExample />
14
16
</ GoogleReCaptchaProvider > ,
15
17
document . getElementById ( 'app' )
16
18
) ;
Original file line number Diff line number Diff line change
1
+ import React , { Component } from 'react' ;
2
+ import {
3
+ IWithGoogleReCaptchaProps ,
4
+ withGoogleReCaptcha
5
+ } from '../src/with-google-recaptcha' ;
6
+
7
+ class ReCaptchaComponent extends Component < { } , { token ?: string } > {
8
+ constructor ( props : { } ) {
9
+ super ( props ) ;
10
+
11
+ this . state = { token : undefined } ;
12
+ }
13
+
14
+ handleVerifyRecaptcha = async ( ) => {
15
+ const { executeRecaptcha } = ( this . props as IWithGoogleReCaptchaProps )
16
+ . googleReCaptchaProps ;
17
+
18
+ if ( ! executeRecaptcha ) {
19
+ console . log ( 'Recaptcha has not been loaded' ) ;
20
+
21
+ return ;
22
+ }
23
+
24
+ const token = await executeRecaptcha ( 'homepage' ) ;
25
+
26
+ this . setState ( { token } ) ;
27
+ } ;
28
+
29
+ render ( ) {
30
+ const { token } = this . state ;
31
+ return (
32
+ < div >
33
+ < h3 > With Google Recaptcha HOC Example</ h3 >
34
+ < button onClick = { this . handleVerifyRecaptcha } > Verify Recaptcha</ button >
35
+ < p > Token: { token } </ p >
36
+ </ div >
37
+ ) ;
38
+ }
39
+ }
40
+
41
+ export const WithGoogleRecaptchaExample =
42
+ withGoogleReCaptcha ( ReCaptchaComponent ) ;
You can’t perform that action at this time.
0 commit comments