-
-
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]: False positive for react/no-unused-prop-types and passthrough #3885
Comments
This is a very strange pattern - why pass a component and a props object around instead of just passing an element directly? Either way, you’re meant to access all of the props individually in each component in which it’s defined, so if you want to write your code this way, then you may need go use an override comment in Component3. |
I didn't include the whole complexity here to keep this example minimal. In the use case, I would be happy to suppress this warning via |
Unfortunately the minimal example doesn't really justify or explain the (uncommon and bizarre) approach - can you provide something a bit more thorough so I can understand why this is a reasonable way to architect your components? |
Here are some additional details on the setup. I cannot show any of the real code, though, since it belongs to a client.
Roughly speaking, the code looks like this (I am skipping some of the typing here): type InnerFilterProps = {
name: string;
computedProperty: /* ... */
};
const CustomFilter: FC<{ Component: FC<InnerFilterProps>; innerProps: InnerFilterProps }> = ({ Component, innerProps, ...customFilterProps }) => {
// complex setup
return (
<outerComponents>
<Component name={props.name} computedProperty={somethingComputedInTheSetup} />
</outerComponents>;
)
}; Now, there are filters declared like const InnerFilterString: FC<InnerFilterProps & StringFilterProps> = (/*...*/) => { /* ... */ };
const CustomFilterString: FC<InnerFilterProps & StringFilterProps> = (props) => {
return <CustomFilter Component={InnerFilterString} props = {props}/>
}
const InnerFilterInteger = /* ... */
// ... more of those Finally, the call in the table library looks roughly like const columns = [
{
// ...
filter: {
Component: CustomFilterString,
customProps: { /* ... */ }
}
}
]
<LibraryTable columns={columns}/> The complexity has multiple reasons:
|
Is there an existing issue for this?
Description Overview
The following code causes a false positive on
react/no-unused-prop-types
:Error:
'name' PropType is defined but prop is never used
.The error goes away when commenting out
Component3
.Expected Behavior
The code above should be accepted by the linter.
eslint-plugin-react version
v7.37.4
eslint version
v8.57.1
node version
v20.15.0
The text was updated successfully, but these errors were encountered: