-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Feat: 3960. Update setFieldValue with setter function #3968
Conversation
🦋 Changeset detectedLatest commit: ec3e471 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
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.
Great idea!
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## formik@2.4.7 ### Patch Changes - [`99dbc24`](99dbc24) [#3968](#3968) Thanks [@ChronicusUA](https://github.com/ChronicusUA)! - Value of setFieldValue can be a function that takes previous field value ## formik-native@2.1.30 ### Patch Changes - Updated dependencies \[[`99dbc24`](99dbc24)]: - formik@2.4.7
Feature for: #3960