Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

ESlint is giving me this warning when I am compiling my code. We are using the AirBNB config.

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

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

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

export default ProfileInterestSkillButtons;
like image 958
Anthony Delgado Avatar asked Jan 05 '18 05:01

Anthony Delgado


People also ask

How do I fix missing in props validation?

To fix ESLint error missing in props validation with React, we can add a comment or disable the rule globally with a config. to disable prop type check for the line immediately below the comment in our code. in . eslintrc to disable the prop type validation rule for the whole project.

Is missing in props validation lint error?

To fix the 'React eslint error missing in props validation' when developing a React app, we can set the prop types of the props in the component causing the error. to import the prop-types package to let us add prop type validation to the Foo component.

How do you validate props in React?

React JS has an inbuilt feature for validating props data type to make sure that values passed through props are valid. React components have a property called propTypes which is used to setup data type validation. Syntax: The syntax to use propTypes is shown below. class Component extends React.

What are propTypes React?

PropTypes are simply a mechanism that ensures that the passed value is of the correct datatype. This makes sure that we don't receive an error at the very end of our app by the console which might not be easy to deal with.


1 Answers

Your component is using a prop named tags that it is receiving from its parent component.

ESLint is just warning you to define a type check for that prop in the component where you are using it. You can do that by either using PropTypes or by using flow.

Simple example using PropType would be:

... // 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

Flow: https://flow.org/en/docs/react/

like image 119
Dangling Cruze Avatar answered Nov 15 '22 04:11

Dangling Cruze