Skip to content

Commit 378a08a

Browse files
committed
refining types definition
1 parent 37411cd commit 378a08a

File tree

3 files changed

+90
-80
lines changed

3 files changed

+90
-80
lines changed

README.md

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,50 +28,91 @@ _See the [`react-native-webview` Getting Started Guide](https://github.com/react
2828

2929
## Usage
3030

31+
With <strong>JavaScript</strong>:
32+
3133
```jsx
32-
import React, { Component, createRef } from 'react';
34+
import React, { useRef } from 'react';
3335
import { View, Button } from 'react-native';
3436

3537
import Recaptcha from 'react-native-recaptcha-that-works';
3638

37-
class App extends Component {
38-
39-
constructor(props) {
40-
super(props);
41-
this.recaptcha = createRef();
42-
}
39+
const App = () => {
40+
const recaptcha = useRef();
4341

44-
send = () => {
42+
const send = () => {
4543
console.log('send!');
4644
this.recaptcha.current.open();
4745
}
4846

49-
onVerify = token => {
47+
const onVerify = token => {
5048
console.log('success!', token);
5149
}
5250

53-
onExpire = () => {
51+
const onExpire = () => {
5452
console.warn('expired!');
5553
}
5654

57-
render() {
58-
return (
59-
<View>
60-
<Recaptcha
61-
ref={this.recaptcha}
62-
siteKey="<your-recaptcha-public-key>"
63-
baseUrl="http://my.domain.com"
64-
onVerify={this.onVerify}
65-
onExpire={this.onExpire}
66-
size="invisible"
67-
/>
68-
<Button title="Send" onPress={this.send} />
69-
</View>
70-
)
55+
return (
56+
<View>
57+
<Recaptcha
58+
ref={recaptcha}
59+
siteKey="<your-recaptcha-public-key>"
60+
baseUrl="http://my.domain.com"
61+
onVerify={onVerify}
62+
onExpire={onExpire}
63+
size="invisible"
64+
/>
65+
<Button title="Send" onPress={send} />
66+
</View>
67+
);
68+
}
69+
```
70+
71+
<details>
72+
<summary>Or with <strong>TypeScript</strong>:</summary>
73+
74+
```tsx
75+
import React, { useRef } from 'react';
76+
import { View, Button } from 'react-native';
77+
78+
import Recaptcha, { RecaptchaHandles } from "react-native-recaptcha-that-works";
79+
80+
// ...
81+
82+
export const Component: React.FC = () => {
83+
const recaptcha = useRef<RecaptchaHandles>();
84+
85+
const send = () => {
86+
console.log('send!');
87+
recaptcha.current?.open();
88+
};
89+
90+
const onVerify = (token: string) => {
91+
console.log('success!', token);
92+
};
93+
94+
const onExpire = () => {
95+
console.warn('expired!');
7196
}
7297

73-
}
98+
return (
99+
<View>
100+
<Recaptcha
101+
ref={recaptcha}
102+
siteKey="<your-recaptcha-public-key>"
103+
baseUrl="http://my.domain.com"
104+
onVerify={onVerify}
105+
onExpire={onExpire}
106+
size="invisible"
107+
/>
108+
<Button title="Send" onPress={send} />
109+
</View>
110+
);
111+
};
74112
```
113+
</details>
114+
115+
<br />
75116

76117
For more details, see the [Sample Project](https://github.com/douglasjunior/react-native-recaptcha-that-works/blob/master/Sample/src/App.js) or try the [Online demo](https://snack.expo.io/@douglasjunior/a6aed2).
77118

@@ -107,42 +148,6 @@ Note: If using `size="invisible"`, then challange run automatically when `open`
107148
- [I'm not a robot](https://developers.google.com/recaptcha/docs/display)
108149
- [Invisible](https://developers.google.com/recaptcha/docs/invisible)
109150

110-
## TypeScript
111-
112-
Example usage in TypeScript project:
113-
114-
```tsx
115-
import Recaptcha, { Handles } from "react-native-recaptcha-that-works";
116-
117-
// ...
118-
119-
export const Component: React.FC = () => {
120-
const recaptcha = React.useRef<Handles>(null);
121-
122-
const send = () => {
123-
console.log('send!');
124-
recaptcha.current?.open();
125-
};
126-
127-
const onVerify = (token: string) => {
128-
console.log('success!', token);
129-
};
130-
131-
return (
132-
<View>
133-
<Recaptcha
134-
ref={recaptcha}
135-
siteKey="<your-recaptcha-public-key>"
136-
baseUrl="http://my.domain.com"
137-
onVerify={onVerify}
138-
size="invisible"
139-
/>
140-
<Button title="Send" onPress={send} />
141-
</View>
142-
);
143-
};
144-
```
145-
146151
## Contribute
147152

148153
New features, bug fixes and improvements are welcome! For questions and suggestions use the [issues](https://github.com/douglasjunior/react-native-recaptcha-that-works/issues).

types.d.ts renamed to index.d.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,32 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
2425
import React, { ReactNode } from "react";
2526
import { StyleProp, ViewStyle } from "react-native";
26-
export declare type Props = {
27-
headerComponent?: ReactNode;
28-
onVerify?: (token: string) => void;
29-
onExpire?: () => void;
30-
onError?: (error: string) => void;
31-
onClose?: () => void;
32-
onLoad?: () => void;
33-
theme?: "dark" | "light";
34-
size?: "invisible" | "normal" | "compact";
35-
siteKey: string;
36-
baseUrl: string;
37-
lang?: string;
38-
style?: StyleProp<ViewStyle>;
27+
28+
export declare type RecaptchaProps = {
29+
headerComponent?: ReactNode;
30+
onVerify?: (token: string) => void;
31+
onExpire?: () => void;
32+
onError?: (error: string) => void;
33+
onClose?: () => void;
34+
onLoad?: () => void;
35+
theme?: "dark" | "light";
36+
size?: "invisible" | "normal" | "compact";
37+
siteKey: string;
38+
baseUrl: string;
39+
lang?: string;
40+
style?: StyleProp<ViewStyle>;
3941
};
40-
export declare type Handles = {
41-
open(): void;
42-
close(): void;
42+
43+
export declare type RecaptchaHandles = {
44+
open(): void;
45+
close(): void;
4346
};
47+
4448
declare const Recaptcha: React.ForwardRefExoticComponent<
45-
Props & React.RefAttributes<Handles>
49+
RecaptchaProps & React.RefAttributes<RecaptchaHandles>
4650
>;
51+
4752
export default Recaptcha;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "react-native-recaptcha-that-works",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"private": false,
55
"description": "⚛ A reCAPTCHA bridge for React Native that works.",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/douglasjunior/react-native-recaptcha-that-works.git"
99
},
1010
"main": "index.js",
11-
"types": "types.d.ts",
11+
"types": "index.d.ts",
1212
"keywords": [
1313
"react-native",
1414
"ios",

0 commit comments

Comments
 (0)