index.js 402 Bytes
Newer Older
zhanghaozhe committed
1 2
import { useEffect } from "react"
import { connect } from "formik"
zhanghaozhe committed
3

zhanghaozhe committed
4 5
const OnSubmissionError = (props) => {
  const { callback, formik } = props
zhanghaozhe committed
6

zhanghaozhe committed
7 8 9
  const effect = () => {
    if (formik.submitCount > 0 && !formik.isValid && !formik.isSubmitting) {
      callback(formik)
zhanghaozhe committed
10
    }
zhanghaozhe committed
11 12 13
  }
  useEffect(effect, [formik.submitCount, formik.isSubmitting])
  return null
zhanghaozhe committed
14 15
}

zhanghaozhe committed
16
export default connect(OnSubmissionError)