-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getResponse returns an empty string #263
Comments
A workaround is to use a ref to store the token value: const SomeForm: React.FC = () => {
const captchaRef = useRef<Reaptcha>(null);
const tokenRef = useRef<string>('');
return (
<Formik
initialValues={{ ... }}
onSubmit={async (values) => {
const token = tokenRef.current;
// Continue with your form submission
}}
>
{({ setSubmitting, submitForm }) => (
<Form>
// Form content, fields, etc,
<Reaptcha
sitekey={''}
ref={captchaRef}
size="invisible"
onVerify={token => {
tokenRef.current = token;
submitForm();
}}
/>
<Button
type="submit"
onClick={() => {
captchaRef.current?.execute();
setSubmitting(true);
}}
>Submit</Button>
</Form>
)}
</Formik>
);
} But I don't see this as very clean |
Hey @nikolakov! Thanks for the reproduction on codesandbox - it helps a lot 😃 The problem here is that For now, unfortunately I don't have any other solution. And the feature I just described will probably not be done (at least by me) in the nearest future 😢 |
I am trying to utilize the getResponse API. In a real world scenario, I want to submit a Formik form. In the submit handler I want to first challenge the user and when ready, continue with the rest of the submission - an API call to the backend containing the token. This approach does not work, as setFieldValue and submit are called in the same render cycle and submit still has the old state at the moment of execution.
I have created a codesandbox isolating the issue:
https://codesandbox.io/s/reaptcha-getresponse-returns-empty-string-zj4754?file=/src/App.tsx
The text was updated successfully, but these errors were encountered: