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(useForm): improve type parameter specification to useForm #6568

Open
wants to merge 4 commits into
base: next
Choose a base branch
from

Conversation

OmkarBansod02
Copy link
Contributor

@OmkarBansod02 OmkarBansod02 commented Dec 10, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

The useForm hook uses a single type parameter for both the form structure and the data submitted to the API. This causes type conflicts when trying to map form data into the structure needed for the API . As a result, developers encounter type errors when attempting to submit transformed data.

What is the new behavior?

After the changes, the useForm hook introduces an additional type parameter for submission data . This separates the form structure type from the submission type . onFinish function correctly expects the SubmissionData type instead of the form structure type. allowing developers to easily map and submit the data without running into type issues.

fixes #6137

Notes for reviewers

Screenshot 2024-12-10 220523

The onValid function is wrapped in onValidWrapper to address a TypeScript error where the form data (TVariables) does not match the expected structure for onValid. This results in a type conflict, so use type casting (variables as unknown as ExtractFormVariables<TVariables>) to ensure the correct form data type is passed to onValid. This resolves the error and ensures type safety during form submission.

@OmkarBansod02 OmkarBansod02 requested a review from a team as a code owner December 10, 2024 16:50
Copy link

changeset-bot bot commented Dec 10, 2024

🦋 Changeset detected

Latest commit: d0ce6ee

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

This PR includes changesets to release 2 packages
Name Type
@refinedev/react-hook-form Minor
@refinedev/core Minor

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

netlify bot commented Dec 10, 2024

Deploy Preview for refine-doc-live-previews ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c3ddaa6
🔍 Latest deploy log https://app.netlify.com/sites/refine-doc-live-previews/deploys/676055c699b73c000871e2ba
😎 Deploy Preview https://deploy-preview-6568--refine-doc-live-previews.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +32 to +33
const FormVariablesSymbol = Symbol("FormVariables");
const SubmissionVariablesSymbol = Symbol("SubmissionVariables");
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here we use Symbol for FormVariables and SubmissionVariables to ensure uniqueness and avoid conflicting with the basic TVariables shape. as Ali mentioned here .

@BatuhanW BatuhanW added this to the January 2025 🎄 milestone Dec 17, 2024
@BatuhanW BatuhanW changed the base branch from main to next December 17, 2024 12:53
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.

[FEAT] Improving Type Parameter Specification in useForm Hook
2 participants