Fix for checkboxes with an initial value of undefined #2188
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
v2.1.1 introduced a bug with checkboxes where they require an initial value in order to work. This is reproducible and is fixed by back-pinning to v2.1.0. Please view this codesandbox:
The
getValueForCheckbox
function inFormik.tsx
was updated to handle checkbox values better, but it introduced a situation where a checkbox with an undefined value would throw an error, sincegetValueForCheckbox
was assuming it was an array.Stack Trace:
Here is the line where it breaks:
formik/packages/formik/src/Formik.tsx
Line 1148 in fee503e
The changes in this PR just shuffle the logic a tiny bit to guarantee this check does not occur unless
currentValue
is an array.resolves #2184