Home > Back-end >  Cannot read properties of undefined (reading 'object') using formik
Cannot read properties of undefined (reading 'object') using formik

Time:09-27

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>
   );
   } 
   }

CodePudding user response:

You need to import Yup correctly as:

import * as Yup from 'yup';
  • Related