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: auto field value update #729

Merged
merged 1 commit into from
Sep 12, 2024
Merged

feat: auto field value update #729

merged 1 commit into from
Sep 12, 2024

Conversation

edmundhung
Copy link
Owner

Fix #600

This is my 2nd attempt to remove the need of passing the key to each input manually by updating the fields value automatically. As mentioned in #728...

It means:

  1. No more warnings from React when spreading the result of getInputProps(), getSelectProps() or getTextareaProps() as it will no longer include a key.
  2. The name will become the only metadata required to be set on your inputs. The initalValue is required only if you care about progressive enhancement.

The main challenge of this change is that Conform will trigger a re-render only when the subscribed metadata is changed and so we don't have a single place that will always re-render and runs the side effect we need. This PR resolves it by running the side effect everywhere we made a subscription and update the relevant fields only if the initialValue is subscribed.

However, the previous solution made an wrong assumption that people will always subscribe to the initialValue when setting up a field which conflicts with (2). As there seems to be no way to associate a field with a subscription, we will either need to re-run the same side effect on every subscription, or, have the useForm() hook subscribed to all key changes so it will always re-render and run the side effect in one single place.

This PR uses the later approach.

Copy link

changeset-bot bot commented Aug 3, 2024

⚠️ No Changeset found

Latest commit: dbddf13

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

cloudflare-workers-and-pages bot commented Aug 3, 2024

Deploying conform with  Cloudflare Pages  Cloudflare Pages

Latest commit: dbddf13
Status: ✅  Deploy successful!
Preview URL: https://04b663ad.conform.pages.dev
Branch Preview URL: https://auto-field-update.conform.pages.dev

View logs

Copy link

pkg-pr-new bot commented Aug 17, 2024

Open in Stackblitz

More templates

@conform-to/dom

pnpm add https://pkg.pr.new/@conform-to/dom@729

@conform-to/react

pnpm add https://pkg.pr.new/@conform-to/react@729

@conform-to/yup

pnpm add https://pkg.pr.new/@conform-to/yup@729

@conform-to/zod

pnpm add https://pkg.pr.new/@conform-to/zod@729

@conform-to/validitystate

pnpm add https://pkg.pr.new/@conform-to/validitystate@729

commit: dbddf13

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.

Warning: A props object containing a "key" prop is being spread into JSX:
1 participant