`FormAtomValues` should accept `FormAtom` instead of `FormAtomFields`
MiroslavPetrik opened this issue · comments
Describe the bug
The naming of FormAtomValues
indicates that given form atom, it will return the form values.
The problem is it accepts form fields, not form object thus making it confusing.
To Reproduce
const userForm = formAtom({
first: fieldAtom({
value: "",
}),
last: fieldAtom({
value: "",
}),
});
type Values = FormAtomValues<typeof userForm> // ERR!
// The helper type in reality accepts `FormAtomFields`
// and thus should be named `FormAtomFieldsValues`
// Currently custom helper is needed!
type FormValues<Form extends FormAtom<any>> = Form extends FormAtom<
infer Fields
>
? FormAtomValues<Fields>
: never;
type Values = FormValues<typeof userForm>
Expected behavior
- the call to
FormAtomValues
should work when givenFormAtom
. - The existent
FormAtomValues
can be renamed toFormFieldsValues
orFieldsValues
orFieldAtomsValues
...
Why this makes sense
- Clear definition of form & fields
fields
is object containing thefieldAtoms
form
is return value offormAtom
which accepts thefields
- Simple forms can be constructed without having a separate variable for the
fields
. Currently I often move the argument back and forth which is not good. - This would be consistent with the hook
useFormAtomValues
which takes formAtom as argument, not form fields.
Additional context
- docs must be updated
Here's the documentation on the API updates:
https://github.com/jaredLunde/form-atoms/blob/acbee934097d90e27a69825dd907e9428a80fce0/README.md#formvalues
Would love your feedback! You've been super insightful and instrumental in improving this library.
I've updated my calls to the new & improved ones and I love it 😍
Thank you for your work.