1
votes

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
Could this be the issue? From there docs: "Thus, this hook will only work if there is a parent Formik React Context from which it can pull from" sourceLogan Anderson
No I couldn't fix it. It says that but it says that it's gonna show a warning, not an error.utiq

1 Answers

0
votes

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