diff --git a/.changeset/khaki-cherries-appear.md b/.changeset/khaki-cherries-appear.md new file mode 100644 index 000000000..91efa474e --- /dev/null +++ b/.changeset/khaki-cherries-appear.md @@ -0,0 +1,5 @@ +--- +'formik': patch +--- + +fix to support number and boolean type for form values diff --git a/packages/formik/src/Formik.tsx b/packages/formik/src/Formik.tsx index 80d868665..e44d56d6d 100755 --- a/packages/formik/src/Formik.tsx +++ b/packages/formik/src/Formik.tsx @@ -599,7 +599,7 @@ export function useFormik({ ); const executeChange = React.useCallback( - (eventOrTextValue: string | React.ChangeEvent, maybePath?: string) => { + (eventOrTextValue: string | number | boolean | React.ChangeEvent, maybePath?: string) => { // By default, assume that the first argument is a string. This allows us to use // handleChange with React Native and React Native Web's onChangeText prop which // provides just the value of the input. @@ -608,7 +608,7 @@ export function useFormik({ let parsed; // If the first argument is not a string though, it has to be a synthetic React Event (or a fake one), // so we handle like we would a normal HTML change event. - if (!isString(eventOrTextValue)) { + if (typeof eventOrTextValue === 'object' && 'nativeEvent' in eventOrTextValue && eventOrTextValue.nativeEvent instanceof Event) { // If we can, persist the event // @see https://reactjs.org/docs/events.html#event-pooling if ((eventOrTextValue as any).persist) {