Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot read properties of undefined (reading 'object') using formik

so this is my first time use formik and Yup and i got this error while using a function:
TypeError
Cannot read properties of undefined (reading ‘object’)

Code:

   import React from "react";
   import "./formikpostup.css";
   import { Formik } from "formik";
   import {Yup} from "yup";

  export default class FormikPostupload extends React.Component{
   uploadPost = Yup.object().shape({
   imageUrl: Yup.string().url().required('A url is required'),
   caption: Yup.string().max(200,'Caption has reached the maximum character limit')
   })

  render(){
    return(
      <div className="formik-upload-parent">
      <div>
      
      </div>
    </div>
   );
   } 
   }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to import Yup correctly as:

import * as Yup from 'yup';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading