Skip to content

Potential Syntax Idea #5

Open
Open
@iamthesiz

Description

@iamthesiz

Hey I think it would be kinda cool if it worked something like this:

const { onSubmit, firstName, lastName } = useForm({
  initialValues: { firstName: 'Alex', lastName: 'Cory' },
  firstName: {
    // A. whatever you return would set whatever the value is for this form input
    onChange: e => {
      return e.target.value
    },
    // B. pull out the stuff you need to set the value. (this way seems more extensible
    onChange: ({ event, value,  set }) => {
      set(event.target.value)
    }
    // you could also have formatters for your value
    value: ({ value, set }) => {
      // do some custom "getter" logic (i.e. say this was a number input)
      // this would be similar to doing `get value() {}` in a class and then doing <input value={this.value} ... />
      set(Number(value))
      // or again, you could just use the "return" value
    }
  },
  lastName: {}
})

<input {...firstName} />

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions