npm formik 0.8.0
v0.8.0

latest releases: 2.4.6, 2.4.5, 2.4.4...
6 years ago

tl;dr

  • No breaking changes, but a few deprecation warnings.
  • New names for some imperative setters
  • validationSchema and Yup are now 100% optional
  • New validate method can handle sync and async custom validators
  • More control over when validation is run

Deprecations (console warnings right now) 🗑

  • Deprecate handleChangeValue. Use setFieldValue instead.
  • Deprecate mapValuesToPayload. Move your function to the top of handleSubmit.
  • Deprecate setError escape hatch with warning. Use setStatus (it's identical and a better name IMHO).

New props and helpers 🍹 ⭐️ 🎉

  • setFieldValue: same as handleChangeValue() except it does not touch the field. Call setFieldTouched right after if you need to
  • setFieldTouched: parallel to setFieldValue, but for touched
  • setFieldError: ...yeah same thing but for errors
  • submitForm: () => void; which lets you submit your form without a dom event (very useful for testing). s/o @ctrlplusb for seeing this as missing way before I did.
  • dirty: boolean as computed prop. true if anything has been touched.
  • status?: any & setStatus: (status: any) => void An escape hatch helper for when you need to set arbitrary state (like a success behavior)

New Formik configuration options ⚙️

  • validate?: (values: Values, props: Props) => { [field: string]: string } | Promise<any> Optional custom validation option. Either return an errors object or and Promise that throws an error object.

  • validateOnChange?: boolean = false. Will fire off validation on change events.

  • validateOnBlur?: boolean = true. Will fire off validation on blur events.

  • moar tests! (like a lot lot lot more)

  • validationSchema is now optional.

Even more badass TypeScript support 🎉

See #74 for details.

I added type safety to all the new setters by restricting their respective keys to Values by using mapped types. As a result, instead of being able to set arbitrary keys on errors and touched, all the setters will now get angry if field(s) are not found in your Values interface.

Old

interface FormikValues {	
 [field: string]: any;		
}

interface FormikErrors {	
 [field: string]: string;		
}

interface FormikTouched {	
 [field: string]: boolean;		
}

New

export interface FormikValues {
  [field: string]: any;
}

export type FormikErrors<Values extends FormikValues> = {
  [Key in keyof Values]?: string
};

export type FormikTouched<Values extends FormikValues> = {
  [Key in keyof Values]?: boolean
};

-Jared

Don't miss a new formik release

NewReleases is sending notifications on new releases.