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

FormAtomValues should accept FormAtom instead of FormAtomFields #28

Closed
MiroslavPetrik opened this issue Feb 1, 2023 · 2 comments
Closed

Comments

@MiroslavPetrik
Copy link
Member

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

  1. the call to FormAtomValues should work when given FormAtom.
  2. The existent FormAtomValues can be renamed to FormFieldsValues or FieldsValues or FieldAtomsValues ...

Why this makes sense

  1. Clear definition of form & fields
    1. fields is object containing the fieldAtoms
    2. form is return value of formAtom which accepts the fields
  2. 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.
  3. This would be consistent with the hook useFormAtomValues which takes formAtom as argument, not form fields.

Additional context

  • docs must be updated
@jaredLunde jaredLunde mentioned this issue Feb 1, 2023
Closed
14 tasks
jaredLunde added a commit that referenced this issue Feb 1, 2023
Refactor library to support Jotai v2 breaking changes. Rename form and field hooks to exclude
"Atom". Rename types to be consistent across the library.

BREAKING CHANGE: Renames form and field hooks to exclude "Atom" and be more terse. Renames most
exported types and several type signatures.

fix #27 #28 #18 #17
@jaredLunde
Copy link
Collaborator

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.

jaredLunde added a commit that referenced this issue Feb 2, 2023
- Refactor library to support Jotai v2 breaking changes. 
- Rename form and field hooks to exclude "Atom". 
- Rename types to be consistent across the library.

BREAKING CHANGE: Renames form and field hooks to exclude "Atom" and be more terse. Renames most
exported types and several type signatures.

fix #27 #28 #18 #17
github-actions bot pushed a commit that referenced this issue Feb 2, 2023
# [2.0.0-next.1](v1.3.0-next.3...v2.0.0-next.1) (2023-02-02)

### Code Refactoring

* upgrade to jotai v2 ([#29](#29)) ([e533e40](e533e40)), closes [#27](#27) [#28](#28) [#18](#18) [#17](#17)

### BREAKING CHANGES

* Renames form and field hooks to exclude "Atom" and be more terse. Renames most
exported types and several type signatures.
@MiroslavPetrik
Copy link
Member Author

I've updated my calls to the new & improved ones and I love it 😍

Thank you for your work.

github-actions bot pushed a commit that referenced this issue Feb 2, 2023
# [2.0.0](v1.2.5...v2.0.0) (2023-02-02)

### Bug Fixes

* empty arrays not included in submit values ([#31](#31)) ([837140d](837140d)), closes [#26](#26)
* fix nested array walk ([#34](#34)) ([448f538](448f538))
* fix package entries ([#24](#24)) ([a18cfc5](a18cfc5))
* fix release ([#22](#22)) ([a4fff3b](a4fff3b))
* fix reset w/ initial value ([#33](#33)) ([8b49243](8b49243))

### Code Refactoring

* upgrade to jotai v2 ([#29](#29)) ([e533e40](e533e40)), closes [#27](#27) [#28](#28) [#18](#18) [#17](#17)

### Features

* add zod validator ([#23](#23)) ([06ca2c4](06ca2c4))
* bump next major ([#35](#35)) ([fb3400e](fb3400e)), closes [#20](#20)
* update build scripts and tests ([#21](#21)) ([b242e02](b242e02))

### BREAKING CHANGES

* Renames form and field hooks to exclude "Atom" and be more terse. Renames most
exported types and several type signatures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants