Input组件的onChange事件不能对外暴露事件对象吗? #5755
-
React默认的onChange事件是可以拿到e: React.ChangeEvent的事件对象的,但是现在好像Input组件内只存了value,导致onChange的时候只能获取到value,而拿不到事件对象? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
你要拿到什么?使用场景能否描述下? |
Beta Was this translation helpful? Give feedback.
-
上面 @zqran 也提到了,其实更多的是最常见的使用场景~ 除此之外的话,这样设计还是为了和其他组件尽量保持一致,避免学习成本和认知成本,因为几乎所有的“表单”类型的组件, 至于 @shervinchen 你所说的希望在某些情况下能接触到原生的事件,其实倒是可以让 Input 的 |
Beta Was this translation helpful? Give feedback.
上面 @zqran 也提到了,其实更多的是最常见的使用场景~
onChange
的第一个参数是string
而不是原生 event,在大多数情况下使用起来都会更简单的一些,毕竟一般情况下,大家是为了取到 input 变化的那个“值”,特别是和 Form 配合使用的时候,会省心很多除此之外的话,这样设计还是为了和其他组件尽量保持一致,避免学习成本和认知成本,因为几乎所有的“表单”类型的组件,
props.value: V
props.onChange(value: V)
props.defaultValue: V
,这三个类型V
都是一致的(例如对应到 Input 组件的话,V
就是string
)至于 @shervinchen 你所说的希望在某些情况下能接触到原生的事件,其实倒是可以让 Input 的
onChange
增加第二个参数:onChange: (value: string, event: Event)