Skip to content
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

Merged

Conversation

ChronicusUA
Copy link
Contributor

Feature for: #3960

Copy link

changeset-bot bot commented Apr 24, 2024

🦋 Changeset detected

Latest commit: ec3e471

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
formik Patch
formik-native Patch

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

Copy link

vercel bot commented Apr 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
formik-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 29, 2024 1:45am

Copy link

codesandbox-ci bot commented Apr 24, 2024

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.

@@ -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;
Copy link

@erashu212 erashu212 May 13, 2024

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

Suggested change
const resolvedValue = isFunction(value) ? value(state.values[field]) : value;
const resolvedValue = isFunction(value) ? value(getIn(state.values, field, '')) : value;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Collaborator

@quantizor quantizor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

@kodiakhq kodiakhq bot merged commit 99dbc24 into jaredpalmer:main Aug 29, 2024
7 of 9 checks passed
@github-actions github-actions bot mentioned this pull request Aug 29, 2024
kodiakhq bot pushed a commit that referenced this pull request Aug 30, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants