Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

formik-yup

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formik-yup

Helpers for Formik with Yup validation

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
651
increased by32.05%
Maintainers
1
Weekly downloads
 
Created
Source

Formik-yup

Formik and Yup is a lovley combination. It just works, and it does what it does really well. But just like any combination of two different frameworks, sometimes you need some help. And that is why I've created this package, containing a few but important helpers for make sure the glue between Formik and Yup is as strong as it possibly can be.

Yup transforms (docs)

When Formik is performing its validation only errors will be returned and managed. Any transforms applied by Yup will therefore not be updating the Formik form values. So, using any transform methods from Yup with Formik will not have any implications on the final submit model. Here are my Yup transform helpers, that will do its best to apply any Yup transforms, and warn for any failed transforms that could not be applied by this package.

Note that any helper functions are async and will return a Promise.

formikFieldApplyYupTransforms

input: value: Value, form: FormikHelpers<any>, validationSchema: Schema, fieldName: string return: formatted value Promise<formattedValue: Value>

Value transform helper for a single field. Useful for applying transforms on, for example, blur or click events. This will modify the value internally, so no manual actions needs to be taken to make sure the form is up to date with the transforms.

Example usage (within a Formik field render):

<TextField
	{...field}
	onBlur={e  => {
		formikFieldApplyYupTransforms(
			field.value,
			form,
			validationSchema,
			field.name
		);
		form.handleBlur(e);
	}}
/>

formikFormApplyYupTransforms

input: values: Payload, form: FormikHelpers<Payload>, validationSchema: Schema return array of the formatted values and an hasErrors boolean: Promise<[formattedValues, hasErrors]>

Value transform helper for a the whole form. Useful for applying transforms on Formik submit. This will modify the value internally, so no manual actions needs to be taken to make sure the form is up to date with the transforms.

Example usage:

const  onSubmit = async (
	values: Payload,
	form: FormikActions<Payload>
) => {
	const [formattedValues, hasErrors] = await  formikFormApplyYupTransforms(
		values,
		form,
		validationSchema
	);

	if (hasErrors) {
		return;
	}

	onSubmit(formattedValues);
};

FAQs

Package last updated on 21 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc