Formik TypeError: Cannot read property 'submitForm' of undefined

Viewed 1484

I'm using useFormikContext like in this example (I'm using NextJS), but the error I get is this "TypeError: Cannot read property 'submitForm' of undefined". The version of Formik I'm using is 2.1.5

This is some code of my component:

import React, { useEffect, useState, useContext } from 'react'
import { useFormikContext, Formik } from 'formik'

import './projects.css';

const ProjectForm = ({ project, ...rest }) => {
  const classes = useStyles()
  const [isSaved, setIsSaved] = useState()
  const { submitForm } = useFormikContext()
  
  .
  .
  .
}

enter image description here

1 Answers

I got the same error. It turned out that I was using a button component outside the Formik Form component.

Related