Error: Data is missing in props validation | eslint (react/prop-types): React

How to resolve error - 'Data is missing in props validation'?

  idkblogs.com      December 15, 2020

Shubham Verma

Shubham Verma


Error: Data is missing in props validation | eslint (react/prop-types): React

S

ometimes we need to write code very neat and clean and sometimes we get some strange error. Here we'll talk about one of the very famous error which is 'Data is missing in props validation'. Sometimes it is hard to resolve. this is a kind of prop-types error in react. In this article, we will see how we can get rid of this error..



In the react app, when we use this.props.XYZ then we get this error, as you can see in the below snapshot:


Error: Data is missing in props validation | eslint (react/prop-types): React

Source: idkblogs.com

Why this error?

The answer is: Because we haven't declared the propTypes and defaultProps in this current component.

Solution:

The solution is, We need to declare the propTypes and defaultProps in this current component.
As you can see in the below snapshot, after declaring the propTypes and defaultProps this error has been removed.

Error: Data is missing in props validation | eslint (react/prop-types): React

Source: idkblogs.com

How to do this?

In your component, if you are using this.props.XYZ, then you have to declare this XYZ in your propTypes and defaultProps object. If these are so many then you can add this by a comma separated as in the below image, and you need to import the code -

import { object, func } from 'prop-types';.

Error: Data is missing in props validation | eslint (react/prop-types): React

Source: idkblogs.com

Thats it. Now you will never worry about this kind of errors in React :)


Thank you

for taking the time to read this article. If you’re interested in Node.js or JavaScript this link will help you a lot.

If you found this article is helpful, then please share this article's link to your friends to whom this is required, you can share this to your technical social media groups also. You can follow us on our social media page for more updates and latest article updates.
To read more about the technologies, Please subscribe us, You'll get the monthly newsletter having all the published article of the last month.