繁体   English   中英

第 5 行:道具验证 react/prop-types 中缺少“标签”

[英]Line 5: 'tags' is missing in props validation react/prop-types

当我编译我的代码时,ESlint 给了我这个警告。 我们正在使用 AirBNB 配置。

import React from 'react';
import { Link } from 'react-router-dom';

const ProfileInterestSkillButtons = ({
    tags, title, user, member,
}) => {

    return (
        <div>
           {title}
        </div>
    );
};

export default ProfileInterestSkillButtons;

您的组件正在使用从其父组件接收的名为tags的道具。

ESLint只是警告您在使用它的组件中为该道具定义类型检查。 您可以使用PropTypesflow

使用PropType的简单示例为:

... // other imports
import PropTypes from 'prop-types';

... // your component declaration

ProfileInterestSkillButtons.propTypes = {
  tags: PropTypes.array.isRequired,
  title: PropTypes.string.isRequired,
  ... // and more
};

export default ProfileInterestSkillButtons;

PropType: https ://reactjs.org/docs/typechecking-with-proptypes.html

流程: https//flow.org/en/docs/react/

使用流程

使用流对道具进行类型检查的快速方法。

// @flow
import React from 'react';
import type { Node } from 'react';
import { SafeAreaView, ScrollView, StatusBar, StyleSheet } from 'react-native';

const ScreenDefaultView = (props: { layout: Node, scrollableLayout?: boolean } ) => {
    const layout = props.layout;
    const scrollableLayout = props.scrollableLayout;
    return ( ...

注意:为了添加可选参数或在 Flow 中调用,可以输入? .

// scrollableLayout? is optional note the ? 
props: { layout: Node, scrollableLayout?: boolean }

流程文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM