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

Initialize FormFieldContext with null for improved type safety #4217

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

davidinoa
Copy link

@davidinoa davidinoa commented Jul 8, 2024

Purpose

This PR refactors the FormFieldContext to use null as its initial value, enhancing type safety and making the component's behavior more predictable.

Origin of the Change

The need for this refactor was discovered when TypeScript and ESLint raised a warning about a potentially unnecessary check in the useFormField hook:

// This check was flagged as potentially unnecessary
if (!fieldContext) {
  throw new Error('useFormField should be used within <FormField>')
}

Changes

  • Modified FormFieldContext initialization to use null instead of an empty object cast to FormFieldContextValue.
  • Updated useFormField hook to handle the potentially null context value.
  • Adjusted TypeScript types to reflect the new context structure.

Potential Impacts

  • This change shouldn't affect existing functionality if the FormField component is used as intended.
  • Improves developer experience by catching potential misuse of the useFormField hook earlier.

Copy link

vercel bot commented Jul 8, 2024

@davidinoa is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

@davidinoa davidinoa marked this pull request as ready for review July 8, 2024 16:00
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.

None yet

1 participant