简体   繁体   中英

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

You need to import Yup correctly as:

import * as Yup from 'yup';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM