jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
34.02k stars 2.79k forks source link

Fix setValue infinite loop issue when it used as useEffect dependency #3715

Closed jadenLog closed 1 year ago

jadenLog commented 1 year ago

Summary This PR is to fix this issue. Fix infinite loop issue when setValue is used in react useEffect hook dependency. The issue should occur with setTouched and setError

Causes When component render, setValue, setTouched, setError arrow function reference is generated as new by getFieldHelpers interface.

Solution Add useMemo to cache these arrow functions. This won't change the function references as long as fieldName is not changed.

References https://github.com/jaredpalmer/formik/issues/3602

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
formik-docs ❌ Failed (Inspect) Feb 28, 2023 at 6:27AM (UTC)