-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
What is the current way of defining the ref for an innerRef attribute using TypeScript? #2290
Comments
Since TypeScript is not really helpful i used
This however makes a non-constant
I do not think this is correct way with 2.x |
We do currently use any. You are free to open a PR to change the innerRef to the signature that I wrote for useRef here: #2222 |
|
@ProteanCode are you using |
Is there any update on this issue? |
seems merged to me. define your innerref like: const myRef = useRef<FormikProps>();
return <Formik innerRef={myRef} {...formikProps} /> if that doesn't work, maybe it hasn't gotten a release? |
That's correct, I missed that release. |
Closing as it seems like we're all good here. InnerRef can be implemented as described here |
last solution doesn't work |
When using typed input: const myRef = React.useRef<FormikProps<YourFormValueType>>(null);
return <Formik<YourFormValueType>
innerRef={myRef}
{...formikProps}
/> |
First of all you need to define a type for interface FormnameInitialValues {
destination_city: string;
cell_phone: string;
}
const initialValues: FormnameInitialValues = {
cell_phone: "",
destination_city: "",
}; Then define a form type for the import { FormikProps } from "formik";
const formikRef = useRef<FormikProps<FormnameInitialValues>>(null); Now you can use all the properties of if (formikRef.current) formikRef.current.resetForm();
if (formikRef.current) formikRef.current.isValid(); |
❓Question
Currently the innerRef has signature of
(instance: any) => void
which does not fit any type I can remind of, likeFormikProps
orFormikHelpers
Before that when I was using the 1.5 version where I could call methods like
setFieldTouched
on the ref therefore an inner Ref should be of typeFormikHelper
or at least inherit it. The(instance: any) => void
looks brokenThe text was updated successfully, but these errors were encountered: