score:2
the problem is in flow annotation in handleClick, i removed this and works fine thanks @alik
score:0
Functional React component. Defined as object. I got this error because I copied and pasted the object from a different with a slightly different name and forgot to change the name of the proptypes object.
FooterIcons.propTypes = {} -> FooterIcon.propTypes
score:0
Instead of disable prop-types
rule, we can introduce children property as part of component props, eg:
import React, { Component } from 'react';
export default class ErrorBoundary extends Component<{ children: React.ReactNode }> {
constructor(props: { children: React.ReactNode }) {
super(props);
this.state = { error: null, errorInfo: null };
}
componentDidCatch(error: Readonly<unknown>, errorInfo: Readonly<unknown>): void {
this.setState({ error, errorInfo });
}
render(): React.ReactElement | React.ReactNode {
const { children } = this.props;
const { error, errorInfo } = this.state as Readonly<Record<string, { componentStack: string }>>;
if (errorInfo)
return (
<details>
<h3>Oops, error detected.</h3>
<p>{error?.toString()}</p>
<p>{errorInfo?.componentStack}</p>
</details>
);
return children;
}
}
Above one is typical example of getting eslint
error gone ~~
Don't worry be happy ~~
score:2
PropTypes checking is a good thing, not recommend to ignore by settings
You can auto generate the propTypes by using vscode React PropTypes Generate extension:
- Select your Component's name
- Press command + . (Windows is Ctrl + .) show Code Actions and select PropTypesGenerate, or press shift + command + alt + P (Windows is shift + ctrl + alt + P) in the macOS
- Input propType to replace default type
score:2
I'm finding eslint to be overly strict in the project I'm working on myself but for this error I fixed it by defining my interface and then implementing as such:
interface myInterface: {
test: string
}
const MyComponent: React.FC<myInterface> = (props: myInterface) => {
score:2
Duplicating my answer from a similar question: https://stackoverflow.com/a/69199304/4290193
eslint-plugin-react@^7.25.0
appears to have resolved the issue for those using React.FC<IProps>
with react/prop-types
validation rule.
So instead of
const Example: React.FC<IProps> = (props: IProps) => ...
This now works without warnings after the update
const Example: React.FC<IProps> = (props) => ...
score:2
On the new version of React and also Next.js, you can simply import PropTypes as follows,
import PropTypes from "prop-types";
and at the bottom of your file add defaultProps and propTypes such as,
Post.defaultProps = {
posts: "",
};
Post.propTypes = {
posts: PropTypes.string,
};
export default Post;
It should resolve your eslint warnings.
score:3
Issue: 'id1' is missing in props validation, eslintreact/prop-types
<div id={props.id1} >
...
</div>
Below solution worked, in a function component:
let { id1 } = props;
<div id={id1} >
...
</div>
Hope that helps.
score:3
Install prop-types package with- npm i prop-types --save
Import it-
import PropTypes from 'prop-types';
Then specify the props, I implemented this way-
export default function Text({ children }) {
Text.propTypes = {
children: PropTypes.node.isRequired,
};
return (
<VStyle className="para">
<p>{children}</p>
</VStyle>
);
}
Also add this in your eslintrc.json or .js file
"rules": {
"react/prop-types": "off"
}
score:4
For me, upgrading eslint-plugin-react to the latest version 7.21.5 fixed this
score:18
I ran into this issue over the past couple days. Like Omri Aharon said in their answer above, it is important to add definitions for your prop types similar to:
SomeClass.propTypes = {
someProp: PropTypes.number,
onTap: PropTypes.func,
};
Don't forget to add the prop definitions outside of your class. I would place it right below/above my class. If you are not sure what your variable type or suffix is for your PropType (ex: PropTypes.number), refer to this npm reference. To Use PropTypes, you must import the package:
import PropTypes from 'prop-types';
If you get the linting error:someProp is not required, but has no corresponding defaultProps declaration
all you have to do is either add .isRequired
to the end of your prop definition like so:
SomeClass.propTypes = {
someProp: PropTypes.number.isRequired,
onTap: PropTypes.func.isRequired,
};
OR add default prop values like so:
SomeClass.defaultProps = {
someProp: 1
};
If you are anything like me, unexperienced or unfamiliar with reactjs, you may also get this error: Must use destructuring props assignment
. To fix this error, define your props before they are used. For example:
const { someProp } = this.props;
score:20
It seems that the problem is in eslint-plugin-react
.
It can not correctly detect what props were mentioned in propTypes
if you have annotated named objects via destructuring anywhere in the class.
There was similar problem in the past
score:65
I know this answer is ridiculous, but consider just disabling this rule until the bugs are worked out or you've upgraded your tooling:
/* eslint-disable react/prop-types */ // TODO: upgrade to latest eslint tooling
Or disable project-wide in your eslintrc:
"rules": {
"react/prop-types": "off"
}
score:115
You need to define propTypes
as a static getter if you want it inside the class declaration:
static get propTypes() {
return {
children: PropTypes.any,
onClickOut: PropTypes.func
};
}
If you want to define it as an object, you need to define it outside the class, like this:
IxClickOut.propTypes = {
children: PropTypes.any,
onClickOut: PropTypes.func,
};
Also it's better if you import prop types from prop-types
, not react
, otherwise you'll see warnings in console (as preparation for React 16):
import PropTypes from 'prop-types';
Source: stackoverflow.com
Related Query
- React eslint error missing in props validation
- React eslint error missing in props validation on for the word "props"
- Eslint - 'match' is missing in props validation (react/prop-types)
- ESLint throws an "is missing in props validation" error when use destructuring in function parameter
- ESLint React PropTypes, 'prop' is missing in prop validation
- React error - "is missing in props validation"
- Using Typescript generics for React Functional Components with eslint props validation
- ESLint missing props validation in Class Component
- How to solve ESLint is missing in props validation in React?
- ESLint - missing return type on function react component - Typescript error explanation
- 'Paramter value' is missing in props validation react/prop-types error
- React Redux missing in props validation and recommended pattern for initialising container from an external API using redux-observable
- error 'document' is not defined : eslint / React
- react/prop-types eslint error in typescript react component
- Route object validation as props in React
- React useCallback linting error missing dependency
- how can I show customized error messaged from server side validation in React Admin package?
- eslint error on deployment on local server of react web app
- eslint error on deployment on local server of react web app
- React redux typescript: connect has missing type error
- Line 5: 'tags' is missing in props validation react/prop-types
- How to find out which react component throws empty props error
- How to solve, craco: *** Cannot find ESLint loader (eslint-loader). *** error with ANTd and React (2021)
- is missing in props validation react/prop-types
- React native jest.preset.js file missing error
- Props is missing from props validation
- Multiple props validation in getDerivedStateFromProps in react js
- React eslint error:Component definition is missing display name
- React Recompose Causing Typescript Error On Props
- React defaultProps doesn't fill missing object props
More Query from same tag
- use a variable in other component in Reactjs
- How can I create a List of items from the API data I get?
- Progressbar re renders previous state when i reset the state
- How to use async-await in onsubmithandler
- Reactjs problems with radio buttons when fetch data
- Using Google Web Fonts With Gatsby and Styled-Components
- React 18 - destroy is not a function
- React reducer works, but once going through the web-page becomes undefined
- Reactjs checkboxes not working in the update state of the component
- Apply styled component style to a third party components
- react-router-dom refresh component when route changes
- Return the full array that include that specific element
- Pass Data from React to node express server
- (swiper/react) Custom Navigation with useRef isn't working correctly
- Redux, callback after synchronous action
- Using Mocha to test props on a rendered SVG component in React
- Add dynamic value beside label in Material UI React Tabs Component
- React - beforeunload event on window does not fire
- Problem with yarn dependencies and material ui component in AWS
- Custom Input Field on datepicker
- Is it OK for a reducer to listen to other actions?
- How to get data from react context
- You should call navigate() in a React.useEffect(), not when your component is first rendered, useNavigate error
- How to change eslint settings to understand absolute import?
- Faded Cards in material-ui crashing web application raising element type is invalid expected a string error
- displaying a result in render from a function in REACTJS
- How can I set a global context in Next.js without getting a "Text content did not match" error?
- Why does useState() duplicate websocket events?
- How do I add a type/interface for nested objects?
- Property 'Choices' does not exist on type 'Promise<IFieldInfo>'