jaredpalmer / formik

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

formik don't detect values change when i use radio buttons #3863

Closed Horion6102 closed 1 year ago

Horion6102 commented 1 year ago

Bug report

Current Behavior

The issue it's my formik don't detect values change when i use radio buttons.

How to reproduce : if you click on radio button nothing happen, like if nothing change in the values, but if click 2 time on the same check box and next to that you change radio button value, you will be able to see the button reload appear, that means formik changes dirty property to true.

Video of issue : https://github.com/jaredpalmer/formik/assets/97897215/dad533ed-d79d-407f-8a7f-d6ea82d9fc2a

Reproducible example

https://codesandbox.io/s/formik-dont-react-r462dq

Suggested solution(s)

We saw that initialValues change at same time as values, it seems to be the origin of the problem because then Formik doesn't see any difference between the two objects.

Your environment

Software Version(s)
Formik 2.4.3
React 17
TypeScript 5.0.4
Browser Chrome Version 115.0.5790.170 (Build officiel) (arm64)
npm/Yarn 6.14.17/1.22.18
Operating System macOs Monterey, version 12.1
yazaldefilimone commented 1 year ago

Let me try fix it

quantizor commented 1 year ago

enableReinitialize is probably the issue, every time initialValues is regenerated it resets the form state.

maxaggedon commented 1 year ago

Just removed enableReinitialize and it still does the same... I have simplified some of the code and added live values and initialValues to make it easy to see they change together until you check/uncheck another person in the example. Only thing I discovered is that initialValues come from a useState call, without it it works fine but we actually need it.

Edit : here is the link https://codesandbox.io/s/formik-dont-react-forked-jn2vlv?file=/index.js