You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All you need to do is [sign up for an API key pair][signup]. You will need the client key.
15
+
All you need to do is [sign up for an API key pair][signup]. You will need the client key then you can use `<ReCAPTCHA />`.
16
16
17
-
You can then use the reCAPTCHA. The default require imports a wrapped component that loads the reCAPTCHA script asynchronously.
17
+
The default usage imports a wrapped component that loads the google recaptcha script asynchronously then instantiates a `reCAPTCHA` the user can then interact with.
18
18
19
+
Here is a simple working [example on codesandbox.io](https://codesandbox.io/s/1y4zzjq37l).
20
+
21
+
Code Example:
19
22
```jsx
20
23
importReCAPTCHAfrom"react-google-recaptcha";
21
24
@@ -25,47 +28,31 @@ function onChange(value) {
25
28
26
29
ReactDOM.render(
27
30
<ReCAPTCHA
28
-
ref="recaptcha"
29
31
sitekey="Your client site key"
30
32
onChange={onChange}
31
33
/>,
32
34
document.body
33
35
);
34
36
```
35
37
36
-
### Rendering Props
38
+
### Component Props
37
39
38
-
Other properties can be used to customise the rendering.
40
+
Properties used to customise the rendering:
39
41
40
42
| Name | Type | Description |
41
43
|:---- | ---- | ------ |
42
44
| sitekey | string | The API client key |
43
45
| onChange | func | The function to be called when the user successfully completes the captcha |
44
-
| theme | enum | *optional*`light` or `dark` The theme of the widget *(__defaults:__ light)*. See [example][docs_theme]
45
-
| type | enum | *optional*`image` or `audio` The type of initial captcha *(__defaults:__ image)*
46
-
| tabindex | number | *optional* The tabindex on the element *(__default:__0)*
46
+
| theme | enum | *optional*`light` or `dark` The theme of the widget *(__defaults:__`light`)*. See [example][docs_theme]
47
+
| type | enum | *optional*`image` or `audio` The type of initial captcha *(__defaults:__`image`)*
48
+
| tabindex | number | *optional* The tabindex on the element *(__default:__`0`)*
47
49
| onExpired | func |*optional* callback when the challenge is expired and has to be redone by user. By default it will call the onChange with null to signify expired callback. |
48
50
| onErrored | func |*optional* callback when the challenge errored, most likely due to network issues. |
49
51
| stoken | string |*optional* set the stoken parameter, which allows the captcha to be used from different domains, see [reCAPTCHA secure-token]|
50
52
| size | enum |*optional*`compact`, `normal` or `invisible`. This allows you to change the size or do an invisible captcha |
51
53
| badge | enum |*optional*`bottomright`, `bottomleft` or `inline`. Positions reCAPTCHA badge. *Only for invisible reCAPTCHA*|
52
54
53
-
54
-
__lang__: In order to translate the reCaptcha widget, you should create a global variable configuring the desired language. If you don't provide it, reCaptcha will pick up the user's interface language.
55
-
56
-
__useRecaptchaNet__: If google.com is blocked, you can set useRecaptchaNet to `true` so that the component uses recaptcha.net instead.
57
-
58
-
__removeOnUnmount__: If you plan to change the lang dynamically, removeOnUnmount should probably be true. This will allow you to unmount the reCAPTCHA component and remount it with a new language.
59
-
60
-
```js
61
-
window.recaptchaOptions= {
62
-
lang:'fr',
63
-
useRecaptchaNet:true,
64
-
removeOnUnmount:false,
65
-
};
66
-
```
67
-
68
-
## Component API
55
+
### Component Instance API
69
56
70
57
The component instance also has some utility functions that can be called. These can be accessed via `ref`.
71
58
@@ -75,23 +62,44 @@ The component instance also has some utility functions that can be called. These
75
62
-`execute()` programmatically invoke the challenge
76
63
- need to call when using `"invisible"` reCAPTCHA - [example below](#invisible-recaptcha)
Starting with 0.7.0, the component now supports invisible options. See the [reCAPTCHA documentation](https://developers.google.com/recaptcha/docs/invisible) to see how to configure it.
90
+
See the [reCAPTCHA documentation](https://developers.google.com/recaptcha/docs/invisible) to see how to configure it.
83
91
84
92
With the invisible option, you need to handle things a bit differently. You will need to call the `execute` method yourself.
85
93
86
94
```jsx
87
95
importReCAPTCHAfrom"react-google-recaptcha";
88
96
89
-
let captcha;
97
+
constrecaptchaRef=React.createRef();
90
98
91
99
ReactDOM.render(
92
100
<form onSubmit={() => { captcha.execute(); }}>
93
101
<ReCAPTCHA
94
-
ref={(el) => { captcha = el; }}
102
+
ref={recaptchaRef}
95
103
size="invisible"
96
104
sitekey="Your client site key"
97
105
/>
@@ -103,6 +111,25 @@ ReactDOM.render(
103
111
104
112
### Advanced usage
105
113
114
+
#### Global properties used by reCaptcha
115
+
116
+
__lang__: By default google reCaptcha infers the user's interface language. In order to overwrite the language and update the translation for the reCaptcha widget, you can create a global variable configuring the desired language via `lang`.
117
+
118
+
__useRecaptchaNet__: If google.com is blocked, you can set `useRecaptchaNet` to `true` so that the component uses recaptcha.net instead.
119
+
120
+
__removeOnUnmount__: If you plan to change the lang dynamically, `removeOnUnmount` should probably be `true`. This unloads the google recaptcha script on `componetWillUnmount` to allow for a new google recaptcha script to load next time the reCAPTCHA component is used to facilitate a new language if needed.
121
+
122
+
Example global properties:
123
+
```js
124
+
window.recaptchaOptions= {
125
+
lang:'fr',
126
+
useRecaptchaNet:true,
127
+
removeOnUnmount:false,
128
+
};
129
+
```
130
+
131
+
#### ReCaptcha loading google recaptcha script manually
132
+
106
133
You can also use the barebone components doing the following. Using that component will oblige you to manage the grecaptcha dep and load the script by yourself.
107
134
108
135
```jsx
@@ -121,7 +148,7 @@ render(
121
148
```
122
149
123
150
## Notes on Requirements
124
-
At least `[email protected]` is required due to `forwardRef` usage in [react-async-script](https://github.com/dozoisch/react-async-script).
151
+
At least `[email protected]` is required due to `forwardRef` usage in the dependency [react-async-script](https://github.com/dozoisch/react-async-script).
0 commit comments