使用React Antial Prop类型与流量



是定义 proptypes 流量的正确方法,以 React-native-native 中的流程?我正在寻找一些准则。

// @flow
import React from 'react';
import { TouchableOpacity, Image, StyleSheet } from 'react-native';
type Props = {
  style?: StyleSheet.Styles,
  onPress: () => mixed,
  source: Image.propTypes.source
};
const IconButton = (props: Props) => (
   <TouchableOpacity onPress={props.onPress}>
     <Image style={props.style} source={props.source} />
   </TouchableOpacity>
);
IconButton.defaultProps = {
  style: {}
};

导出默认ICONBUTTON;

我如何使用它是这样的例子:

<IconButton
    onPress={()=>{}}
    style={this.props.style}
    source={require('./assets/images/circle.png')}
 />

随着流的流动,您不一定需要proptypes -Flow会照顾您的输入类型检查。

但是,如果您仍然想要生成Proptypes的运行时警告,则可以使用Babel-Plugin-Flow-follow-reacttypes babel插件来自动根据您的流量Props类型定义生成proptypes。

最新更新