@@ -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' ;
3335import { View , Button } from ' react-native' ;
3436
3537import 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
76117For 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
148153New features, bug fixes and improvements are welcome! For questions and suggestions use the [ issues] ( https://github.com/douglasjunior/react-native-recaptcha-that-works/issues ) .
0 commit comments