Skip to content
Advertisement

React eslint error missing in props validation on for the word “props”

I have the code below:

JavaScript

I am getting the error; “job” is missing in props validation react/prop-types, but this ONLY happens if I use the word “props” as a parameter. If I change it to anything else even “prop”, the error goes away. Does anyone know why this is and how to fix it to be able to use “props” as a parameter?

Advertisement

Answer

Prop validations is a way of typechecking the props that a component recieves.

For instance, in the case of BirthdayCard you could do something like:

JavaScript

So whenever you use BirthdayCard and pass the prop job with a type other than string you will get a console error warning you that the type should be string.

JavaScript

If you are not going to be defining prop types you might want to disable this warning.

As of why it only throws the warning when the name is props, I have no clue. Maybe because it’s a convention to use the name props.

Side note. You can use object deconstruction to clean your component definitions a little bit.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement