New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: 3960. Update setFieldValue with setter function #3968
base: main
Are you sure you want to change the base?
Feat: 3960. Update setFieldValue with setter function #3968
Conversation
🦋 Changeset detectedLatest commit: 0f98bec The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
19ebc1f
to
d7af688
Compare
packages/formik/src/Formik.tsx
Outdated
@@ -582,18 +582,20 @@ export function useFormik<Values extends FormikValues = FormikValues>({ | |||
); | |||
|
|||
const setFieldValue = useEventCallback( | |||
(field: string, value: any, shouldValidate?: boolean) => { | |||
(field: string, value: React.SetStateAction<any>, shouldValidate?: boolean) => { | |||
const resolvedValue = isFunction(value) ? value(state.values[field]) : value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use getIn
instead of value(state.values[field])
.
E.g
const resolvedValue = isFunction(value) ? value(state.values[field]) : value; | |
const resolvedValue = isFunction(value) ? value(getIn(state.values, field, '')) : value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Feature for: #3960