第5行:道具验证react / prop-types中缺少'tags'

问题描述 投票:0回答:1

当我编译代码时,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;
javascript reactjs webpack eslint eslint-config-airbnb
1个回答
1
投票

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

ESLint只是警告您在使用它的组件中为该prop定义类型检查。您可以使用PropTypes或使用flow来实现。

使用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;

演讲:赌场

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

© www.soinside.com 2019 - 2024. All rights reserved.