Skip to content

Why use listeners and not just onChange? #1046

Discussion options

You must be logged in to vote

It's really cool seeing people discuss the api 🤟

Well as you mentioned the separation of concerns, but also because onChange isn't the only event you can subscribe to.

  • onChange
  • onBlur
  • onMount
  • onSubmit

All those events can be subscribed to in the listeners api, could you imagine what your component would look like trying to subscribe to these events... And as everyone else has mentioned, handleChange should handle the change of the field value, its nice to be able to separate out the logic when you have dependent fields.

It also allows you to abstract away your components from the form field logic, so your NumberInput component doesn’t need to account for how it relates to other form fie…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@bennettdams
Comment options

@harry-whorlow
Comment options

Answer selected by bennettdams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants