简体   繁体   English

如何在React中触发本机事件?

[英]How to trigger native event in React?

I'm creating a custom input tag, PhoneInput . 我正在创建一个自定义输入标签PhoneInput It has 3 inputs inside, so I need to parse them, and concat back to string. 它里面有3个输入,所以我需要解析它们,然后重新连接到字符串。 I want to pass in onChange callback SyntheticEvent , like React does. 我想传入onChange回调SyntheticEvent ,就像React一样。 So I need to create hidden input: 所以我需要创建隐藏的输入:

<input onChange={this.props.onChange} value={this.state.value}/>

But when I change state, event didn't triggers. 但是当我改变状态时,事件没有触发。 How to do it right? 怎么做对了? http://jsbin.com/bahuyuriqa/1 - here is example. http://jsbin.com/bahuyuriqa/1 - 这是一个例子。

Change events, it seems, are only fired from user input. 看来,更改事件只会从用户输入中触发。 Is there a specific reason you would need an onChange handler on the hidden input? 您是否需要在隐藏输入上使用onChange处理程序? If you do need access to the native event from the synthetic event , you can simply access it via e.nativeEvent 如果确实需要从合成事件访问本机事件 ,则只需通过e.nativeEvent访问它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM