2016-11-15 7 views
0

私はこのeslintエラーが私に求めていることを理解しています。私はapolloクライアントのデモコードを使用していて、 "データ"が好きではないようです。function PostList({ data: { loading, posts } }) {eslintエラー "データが小道具の検証に欠落しています" apolloの反応アプリ

私はairbnb eslintのルールに従うために何か他のことを行うべきですか、それとも無視してください。

import React from 'react'; 
import { Text, View } from 'react-native'; 
import { graphql } from 'react-apollo'; 
import gql from 'graphql-tag'; 

const styles = { 
    outer: { paddingTop: 22 }, 
    wrapper: { height: 45, flex: 1, flexDirection: 'row' }, 
    header: { fontSize: 20 }, 
    subtextWrapper: { flex: 1, flexDirection: 'row' }, 
    votes: { color: '#999' }, 
} 

// The data prop, which is provided by the wrapper below contains, 
// a `loading` key while the query is in flight and posts when ready 
function PostList({ data: { loading, posts } }) { 
    if (loading) { 
    return <Text style={styles.outer}>Loading</Text>; 
    } else { 
    return (
     <View style={styles.outer}> 
     {posts.sort((x, y) => y.votes - x.votes).map(post => (
      <View key={post.id} style={styles.wrapper}> 
      <View> 
       <Text style={styles.header}>{post.title}</Text> 
       <View style={styles.subtextWrapper}> 
       <Text> 
       by {post.author.firstName} {' '} 
       {post.author.lastName} {' '} 
       </Text> 
       <Text style={styles.votes}>{post.votes} votes</Text> 
       </View> 
      </View> 
      </View> 
     ))} 
     </View> 
    ); 
    } 
} 

// The `graphql` wrapper executes a GraphQL query and makes the results 
// available on the `data` prop of the wrapped component (PostList here) 
export default graphql(gql` 
    query allPosts { 
    posts { 
     id 
     title 
     votes 
     author { 
     id 
     firstName 
     lastName 
     } 
    } 
    } 
`)(PostList); 

答えて

0

あなたのファイルにproptypesを追加する必要があります。

PostList.propTypes = { 
    data: React.PropTypes.object, 
}; 

は、あなたのPostList機能の下にこれを追加します。 PropTypeは、Reactアプリケーションのコンポーネントに渡されるデータ型を検証する方法です。

AirBnBリンターは、このことをベストプラクティスとして保証します。

+0

もう1つのlintエラー - プロップタイプのオブジェクトは禁止されています – MonkeyBonkey

+0

あなたは 'React.PropTypes.any'を使用することができ、それは検証に合格します。しかし、あなたが渡しているものはPropTypeとして宣言したものです。 – Toby

+0

また、禁止されている小道具タイプの詳細については、この[link](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md)をチェックしてください特定のリンター設定に依存します。 – Toby

関連する問題