File tree Expand file tree Collapse file tree 1 file changed +21
-7
lines changed Expand file tree Collapse file tree 1 file changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -150,21 +150,35 @@ import {
150
150
withGoogleReCaptcha
151
151
} from ' react-google-recaptcha-v3' ;
152
152
153
- class ReCaptchaComponent extends React .Component {
154
- async componentDidMount () {
155
- const token = await this .props .googleReCaptchaProps .executeRecaptcha (' homepage' );
156
- }
153
+ class ReCaptchaComponent extends Component < {}> {
154
+ handleVerifyRecaptcha = async () => {
155
+ const { executeRecaptcha } = (this .props as IWithGoogleReCaptchaProps)
156
+ .googleReCaptchaProps ;
157
+
158
+ if (! executeRecaptcha) {
159
+ console .log (' Recaptcha has not been loaded' );
160
+
161
+ return ;
162
+ }
163
+
164
+ const token = await executeRecaptcha (' homepage' );
165
+ };
157
166
158
167
render () {
159
- ...
168
+ return (
169
+ < div>
170
+ < button onClick= {this .handleVerifyRecaptcha }> Verify Recaptcha< / button>
171
+ < / div>
172
+ );
160
173
}
161
174
}
162
175
163
- const YourReCaptchaComponent = withGoogleReCaptcha (ReCaptchaComponent);
176
+ export const WithGoogleRecaptchaExample =
177
+ withGoogleReCaptcha (ReCaptchaComponent);
164
178
165
179
ReactDom .render (
166
180
< GoogleReCaptchaProvider reCaptchaKey= " [Your recaptcha key]" >
167
- < YourReCaptchaComponent / >
181
+ < WithGoogleRecaptchaExample / >
168
182
< / GoogleReCaptchaProvider> ,
169
183
document .getElementById (' app' )
170
184
);
You can’t perform that action at this time.
0 commit comments