第 5 行:道具验证 react/prop-types 中缺少 'tags'
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 只是警告您在使用它的组件中为该道具定义类型检查。您可以使用 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
使用流程
使用流程对 props 进行类型检查的快速方法。
// @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 }
流文档
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 只是警告您在使用它的组件中为该道具定义类型检查。您可以使用 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
使用流程
使用流程对 props 进行类型检查的快速方法。
// @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 }