SHARE
TWEET

Untitled

a guest Jun 16th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // @flow
  2.  
  3. //...
  4.  
  5. interface DatasourceItem {
  6.   key: string;
  7.   isLiked: boolean;
  8. }
  9.  
  10. type Props<T: DatasourceItem> = {
  11.   items: Array<T>,
  12.   renderItem: (T, (T) => void) => React$Node,
  13.   //...
  14. };
  15.  
  16. type State<T: DatasourceItem> = {
  17.   items: Array<T>,
  18. };
  19.  
  20. export default class ProductList<T: DatasourceItem> extends React.PureComponent<Props<T>,State<T>> {
  21.   constructor(props: Props<T>) {
  22.     super(props);
  23.     this.state = {
  24.       items: this.props.items,
  25.     };
  26.   }
  27.  
  28.   render() {
  29.     return (
  30.       <FlatList
  31.         style={styles.list}
  32.         data={this.state.items}
  33.         renderItem={this.renderCardItem}
  34.       />
  35.     );
  36.   }
  37.  
  38.   renderCardItem = (data: { item: T }) => {
  39.     const item = data.item;
  40.     return (...);
  41.   };
  42. }
  43.      
  44. Cannot create `FlatList` element because `DatasourceItem` [1] is incompatible with `T` [1] in property `item` of the first argument of property `renderItem`. (References: [1])flow
  45. Cannot create `FlatList` element because `T` [1] is incompatible with `DatasourceItem` [2] in property `item` of the first argument of property `renderItem`. (References: [1] [2])flow
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top