我目前正在使用flow和eslint清理我们的代码库。
Eslint告诉您将无状态组件转换为无状态功能组件。但我还没有找到一个例子来说明他们的道具是如何正确键入flow的。以下是我尝试的内容:
原始组件:
type Props = {onPress : Function}
export default class MyButton extends React.Component <Props> {
render() {
... // use this.props.onPress
}
}
版本1(我期望函数如何工作):
此处flow表示
Cannot create MyButton element because a callable signature is missing in props [1] but exists in function type [2].
const MyButton = (onPress: Function) => (
return(
... // use onPress
)
}
版本2(如所示
here
):
eslint抱怨说
onPress
找不到。
${onPress}
也不起作用。
流量投诉:
Missing type annotation for destructuring.
const MyButton = ({onPress: Function}) => (
return(
... // use onPress (or ${onPress} ??)
)
}
那么我该如何解决这个问题呢?