Skip to content

Commit f5cd200

Browse files
committed
docs: update withGoogleRecaptcha example
1 parent 6f0af75 commit f5cd200

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,35 @@ import {
150150
withGoogleReCaptcha
151151
} from 'react-google-recaptcha-v3';
152152

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+
};
157166

158167
render() {
159-
...
168+
return (
169+
<div>
170+
<button onClick={this.handleVerifyRecaptcha}>Verify Recaptcha</button>
171+
</div>
172+
);
160173
}
161174
}
162175

163-
const YourReCaptchaComponent = withGoogleReCaptcha(ReCaptchaComponent);
176+
export const WithGoogleRecaptchaExample =
177+
withGoogleReCaptcha(ReCaptchaComponent);
164178

165179
ReactDom.render(
166180
<GoogleReCaptchaProvider reCaptchaKey="[Your recaptcha key]">
167-
<YourReCaptchaComponent />
181+
<WithGoogleRecaptchaExample />
168182
</GoogleReCaptchaProvider>,
169183
document.getElementById('app')
170184
);

0 commit comments

Comments
 (0)