admin 管理员组文章数量: 1086019
I have a React Component with an onChange
handler:
// @flow
import React, {Component} from 'react';
export default class MyList extends Component {
handleChange = (event) => {
// Do something with event.target.value
// which will be the value typed in the input field.
}
render() {
return (
<input type="text" onChange={this.handleChange}> />
);
}
}
and Flow plains about this because it is an exported class:
Parameter `event` missing annotation
How can I annotate the event
parameter in the handleChange function? As far as I know, this event is generated at the JavaScript level and doesn't have any Flow typing.
Alternatively, can Flow be configured to not display these "missing annotation" errors?
I have a React Component with an onChange
handler:
// @flow
import React, {Component} from 'react';
export default class MyList extends Component {
handleChange = (event) => {
// Do something with event.target.value
// which will be the value typed in the input field.
}
render() {
return (
<input type="text" onChange={this.handleChange}> />
);
}
}
and Flow plains about this because it is an exported class:
Parameter `event` missing annotation
How can I annotate the event
parameter in the handleChange function? As far as I know, this event is generated at the JavaScript level and doesn't have any Flow typing.
Alternatively, can Flow be configured to not display these "missing annotation" errors?
Share Improve this question asked Nov 8, 2016 at 18:51 Ryan H.Ryan H. 7,8644 gold badges41 silver badges46 bronze badges2 Answers
Reset to default 5I found another solution, using synthetic events: something like the following
onChange (event: SyntheticInputEvent<EventTarget>): void {
this.setState({ text: event.target.value })
}
You can find the typings here https://github./facebook/flow/blob/master/lib/dom.js
handleChange = (event: Event) => {
if (event.target instanceof HTMLInputElement) {
console.log(event.target.value)
}
}
本文标签: javascriptHow should an onChange event be annotated in an exported React ComponentStack Overflow
版权声明:本文标题:javascript - How should an onChange event be annotated in an exported React Component? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1743995268a2515459.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论