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(core): docs for reusable fields & reusable field utility type #1084

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

Conversation

harry-whorlow
Copy link
Contributor

A continue on from #636, this PR introduces docs for reusable components/fields as well as introduces a Ts utility type for inferring valid field names, for the relevant component.

Much like my last PR this is something I was trying to do for a work project, but not having any docs or examples hindered the process, so I figured I'd give it a go.


Guidance wanted:

Specifically with this line onChange={(e) => handleChange(e.target.value as any)} (line 28 in reusable-fields) I can't stand the casting of any, however I can figure a way for Ts to infer this value. Any suggestions is greatly appreciated!


Sandbox

I have a code sandbox for playing around with this here, you'll see theres a folder called solutions that has two files:

  • one.tsx works and is a refined version of all my test components
  • two.tsx is another version that I haven't quite got working but in terms of user Ux I think is an improvement.

The rest of the files can be ignored but if you want to see how I got here they kind of explain my reasoning.

@harry-whorlow harry-whorlow marked this pull request as draft December 20, 2024 12:59
Copy link

nx-cloud bot commented Dec 20, 2024

View your CI Pipeline Execution ↗ for commit 524d024.

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ❌ Failed 3m 17s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 29s View ↗

☁️ Nx Cloud last updated this comment at 2024-12-22 16:19:33 UTC

Copy link

pkg-pr-new bot commented Dec 20, 2024

Open in Stackblitz

More templates

@tanstack/angular-form

npm i https://pkg.pr.new/@tanstack/angular-form@1084

@tanstack/react-form

npm i https://pkg.pr.new/@tanstack/react-form@1084

@tanstack/form-core

npm i https://pkg.pr.new/@tanstack/form-core@1084

@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-form@1084

@tanstack/lit-form

npm i https://pkg.pr.new/@tanstack/lit-form@1084

@tanstack/valibot-form-adapter

npm i https://pkg.pr.new/@tanstack/valibot-form-adapter@1084

@tanstack/vue-form

npm i https://pkg.pr.new/@tanstack/vue-form@1084

@tanstack/yup-form-adapter

npm i https://pkg.pr.new/@tanstack/yup-form-adapter@1084

@tanstack/zod-form-adapter

npm i https://pkg.pr.new/@tanstack/zod-form-adapter@1084

commit: 524d024

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.75%. Comparing base (91eb9ab) to head (f283513).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1084      +/-   ##
==========================================
+ Coverage   86.61%   86.75%   +0.13%     
==========================================
  Files          29       29              
  Lines        1158     1155       -3     
  Branches      301      298       -3     
==========================================
- Hits         1003     1002       -1     
+ Misses        142      140       -2     
  Partials       13       13              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@harry-whorlow harry-whorlow marked this pull request as ready for review December 20, 2024 13:47
@harry-whorlow harry-whorlow force-pushed the reusable-fields branch 2 times, most recently from 4256a04 to 8f9ac02 Compare December 20, 2024 13:54
@harry-whorlow harry-whorlow force-pushed the reusable-fields branch 2 times, most recently from 92b67c7 to 616d520 Compare December 20, 2024 13:58
@harry-whorlow
Copy link
Contributor Author

Sorry for the push forces... was looking at the incorrect section of code and wondering why it wasn't changing. Friday’s for you 🙃

/**
* The return type use useForm with pre-populated generics
*/
export type UseFormReturnType<TForm, TFormValidator> = TFormValidator extends
Copy link
Contributor Author

@harry-whorlow harry-whorlow Dec 22, 2024

Choose a reason for hiding this comment

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

I would love to get rid of the TFormValidator slot, since TFormValidator is just Validator<TForm, unknown> | undefined. But so far my efforts have been fruitless.

{({ handleChange, handleBlur, state }) => (
<input
value={state.value}
onChange={(e) => handleChange(e.target.value as any)}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another improvement would be to get Ts to infer the handleChange value so the update is type safe.

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.

1 participant