jaredpalmer / formik

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

enableReinitialize triggers render twice #3316

Open energizer91 opened 3 years ago

energizer91 commented 3 years ago

Bug report

Current Behavior

When settings enableReinitialize Formik renders twice (instead rendering once as it was in version 1.5.8 for example)

Expected behavior

Formik should render once if nothing changed during first render

Reproducible example

https://codesandbox.io/s/formik-codesandbox-template-forked-goq55 (open console and see how many render messages you see)

Suggested solution(s)

Probably, the problem is located here: https://github.com/formium/formik/blob/master/packages/formik/src/Formik.tsx#L166 Not sure why we need isMounted at all (and why it's ref and not state), even though checking isMounted in useEffect with additional props array (since it will be called only after first render)

Additional context

Your environment

Software Version(s)
Formik 2.2.9
React 17.0.0.2
TypeScript 4.3.5
Browser Chrome 92
npm/Yarn 1.22.5
Operating System MacOS 11.4
iiKulakov commented 4 months ago

Any news on this? Same problem as: https://stackoverflow.com/questions/73737311/formik-renders-twice-on-initialization