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

Potential Syntax Idea #5

Open
alex-cory opened this issue May 24, 2019 · 2 comments
Open

Potential Syntax Idea #5

alex-cory opened this issue May 24, 2019 · 2 comments

Comments

@alex-cory
Copy link
Contributor

alex-cory commented May 24, 2019

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} />
@alex-cory
Copy link
Contributor Author

You could also do B without the set function. I think that might be the cleanest, but whatever works :)

@amazingandyyy
Copy link
Owner

That's really innovative!

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

No branches or pull requests

2 participants