Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Yup on React Native throws unhandled promise rejection warning when validation fails #2113

Closed
cameronmurphy opened this issue Dec 12, 2019 · 3 comments

Comments

@cameronmurphy
Copy link

cameronmurphy commented Dec 12, 2019

馃悰 Bug report

Current behavior

2019-12-12 13 58 42

About 1 or 2 seconds after validation fails a promise is rejected with the errors object.

Possible Unhandled Promise Rejection (id: 0):
Object {
  "test": "test is a required field",
}

Expected behavior

I'd expect no unhandled promise rejections.

Reproducible example

Steps to reproduce:

npm install -g expo-cli
expo init formik-yup-test
cd formik-yup-test
yarn add formik yup

Copy this code into App.js

import { Button, StyleSheet, Text, TextInput, View } from 'react-native';
import { Formik } from 'formik';
import * as Yup from 'yup';
import React from 'react';

const schema = Yup.object().shape({
  test: Yup.string().required(),
});

export default function App() {
  return (
    <View style={styles.container}>
      <Formik initialValues={{ test: '' }} onSubmit={values => console.log(values)} validationSchema={schema}>
        {({ errors, handleChange, handleBlur, handleSubmit, values }) => (
          <>
            <TextInput
              onBlur={handleBlur('test')}
              onChangeText={handleChange('test')}
              style={styles.textInput}
              value={values.test}
            />
            <Text style={styles.errors}>{JSON.stringify(errors)}</Text>
            <Button onPress={handleSubmit} title="Submit" />
          </>
        )}
      </Formik>
    </View>
  );
}

const styles = StyleSheet.create({
  errors: {
    textAlign: 'center',
  },
  textInput: {
    alignSelf: 'stretch',
    borderColor: 'black',
    borderWidth: 1,
    fontSize: 20,
    marginBottom: 10,
  },
  container: {
    flex: 1,
    backgroundColor: '#fff',
    padding: 20,
  },
});

Run yarn start and open in the iOS Simulator.

Suggested solution(s)

Avoid rejecting promises or document how the user can avoid this warning. The example form was based on the documentation here https://jaredpalmer.com/formik/docs/guides/react-native

Your environment

Software Version(s)
Formik 2.0.7
Yup 0.27.0
React 16.9
npm/Yarn Yarn 1.19.2
Operating System macOS 10.15.1
@dennis-tagomi
Copy link

this is caused by combineErrors and has been rolled back in 2.0.8 hotfix

@jaredpalmer
Copy link
Owner

Fixed in 2.1

@kasaiee
Copy link

kasaiee commented Sep 9, 2023

I have this in yup@1.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants