Open pnrBehnamm opened 4 years ago
Did you tried <Formik<Type> {...}>
?
withFormik<
OuterProps extends object,
Values extends FormikValues,
Payload = Values
>
signature suggests it can be done. Second argument is for type of your object you want.
I have used Render props (<Formik /> and <Field />)
and I fixed my issue.
import * as React from 'react';
import {
Formik,
FormikHelpers,
FormikProps,
Form,
Field,
FieldProps,
} from 'formik';
interface MyFormValues {
firstName: string;
}
export const MyApp: React.FC<{}> = () => {
const initialValues: MyFormValues = { firstName: '' };
return (
<div>
<h1>My Example</h1>
<Formik
initialValues={initialValues}
onSubmit={(values, actions) => {
console.log({ values, actions });
alert(JSON.stringify(values, null, 2));
actions.setSubmitting(false);
}}
render={formikBag => (
<Form>
<Field
name="firstName"
render={({ field, form, meta }) => (
<div>
<input type="text" {...field} placeholder="First Name" />
{meta.touched && meta.error && meta.error}
</div>
)}
/>
</Form>
)}
/>
</div>
);
};
Linking this nice blog post to this thread https://spin.atomicobject.com/2020/10/25/formik-type-safe-paths/
I tried to add strongly typed in Formik react library by typescript, but I didn't do that. Of course, I have used this link, but I couldn't solve my issue. https://jaredpalmer.com/formik/docs/guides/typescript
I have got this error from this part of code(})(ActivityForm);):