-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: react/prop-types
false positive when component is a value of capitalized property in class
#3534
Comments
react/prop-types
false positive when component is a value of capitalized propertyreact/prop-types
false positive when component is a value of capitalized property in class
|
The reason it's named Here's a more complete example of how we use it: import React, { Component } from 'react';
import ReactTable from 'react-table';
export default class MyTable extends Component {
columns = [
{
Cell: ({ original }: { original: string }) => <span>{original === 'bla' ? 'bla' : 'bla'}</span>,
},
];
render(): JSX.Element {
return <ReactTable columns={this.columns} />;
}
} Note that we're using |
and ReactTable requires it to be named "Cell"? is that because it uses it like a component? |
Yes, see:
from docs
I think so... |
right - so, it's a component. and components should have propTypes. Is there a reason you can't do: import React from 'react';
class SomeComponent {
column = {
Cell({ original }: { original: string }) { return <span>{original === 'bla' ? 'bla' : 'bla'}</span>; },
};
} ? Components shouldn't be arrow functions, and I think that should be recognized by the prop-types rule as having prop types. (even better is to define it outside of SomeComponent and reuse it) |
Hi, @ljharb just curious if you had time to look into this or have any thoughts. |
I haven't had time to look into it. Yes, it's a stylistic preference, but it's more than just that, because an arrow function can't ever have an explicit name, and name inference isn't always intuitive. |
I think I've experienced a similar issue. In my situation I have an HOC: const ModifiedComponent = withModifiedBehavior(Component, options); The interface WithModifiedBehaviorOptions {
// ...
ModifiedBehaviorComponent?: React.ComponentType<{propWhichWillBePassed: () => void}>;
// ...
}
const ModifiedComponent = withModifiedBehavior(Component, {
ModifiedBehaviorComponent ({ propWhichWillBePassed }) {
return (<>
<div>Custom Text</div>
<button
onClick={
// custom logic
propWhichWillBePassed()
}
/>
</>)
}
}); In this case The TS validation works perfectly fine here and it's able to infer the type and give all the necessary intellisense. I've tried declaring the In this case I'm not sure if there's a method for adding prop types to a Function Component provided as an object property. Obviously I could export the type |
Is there an existing issue for this?
Description Overview
Weird error:

eslint myfile.tsx
Expected Behavior
Not to throw error
When I change
Cell
tocell
- the error is gone.When I avoid using destructuring - the error is also gone.
eslint-plugin-react version
v7.32.2
eslint version
v8.34.0
node version
v18.14.1
The text was updated successfully, but these errors were encountered: