-
-
Notifications
You must be signed in to change notification settings - Fork 304
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
update react-hook-form
column in comparision table
#673
Conversation
Do we actually know that hook form is fully inferred all the way down to nested and deep fields? |
docs/comparison.md
Outdated
| Granular reactivity | ✅ | ❓ | ❓ | ❓ | ❓ | | ||
| Nested object/array fields | ✅ | ✅ | ❓ | ❓ | ❓ | | ||
| Nested object/array fields | ✅ | ✅ | ❓ | ✅ | ❓ | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I could put a tooltip here, I'd say while it suppors nested arrays but useFeildArray
supports one level nesting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use a *(1) callout with a corresponding footnote
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially thought it was unsupported, but after rechecking the documentation, it appears to be a TypeScript issue.
for nested field array, you will have to cast the field array by its name.
const { fields } = useFieldArray({ name: `test.${index}.keyValue` as 'test.0.keyValue' });
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add the *(1)
callout here, then I'm okay to merge this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it still needed after 👇?
I initially thought it was unsupported, but after rechecking the documentation, it appears to be a TypeScript issue.
for nested field array, you will have to cast the field array by its name.
const { fields } = useFieldArray({ name: `test.${index}.keyValue` as 'test.0.keyValue' });
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the *
I'm hoping for - type casting is an obtuse way of supporting this that we don't require
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See 99a07ff
(#673)
BTW, feel free to edit it yourself
Yeah. When you pass a generic it infer everything from it: const form = useForm<FormType>({
// all props here infer FormType
});
// ^? UseFormReturn<FormType> all method and values of |
Generic casting isn’t ideal. How does it do with actual inference? |
one trade of is with arrays: let's say you have interface FormType {
array: { key: string }[]
} The way you access the |
const { name, onChange, onBlur, ref } = form.register("age", { validate: async (value, _formValues) => { await new Promise((resolve) => setTimeout(resolve, 1000)); return value > 12 ? true : "error message"; }, });
| Nested object/array fields | ✅ | ✅ | ❓ | ❓ | ❓ | | ||
| Async validation | ✅ | ✅ | ❓ | ❓ | ❓ | | ||
| Nested object/array fields | ✅ | ✅ | ❓ | ✅ | ❓ | | ||
| Async validation | ✅ | ✅ | ❓ | ✅ | ❓ | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { name, onChange, onBlur, ref } = form.register("a", {
validate: async (value, _formValues) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
return value === "error" ? "error message" : undefined /* or true */;
},
});
Thanks for this! |
It's better to review this in unified mode with wide screen or scale down