-
-
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
Deconstructing function arguments violates no-unused-prop-types rule #2947
Comments
I'm a bit confused. |
A PR to improve component detection so this isn't considered a component would be welcome. |
I'm going to close this since useCallback is not meant for components (that's Happy to reopen if there's a PR with failing test cases. |
If you are working with a component that accepts render props then you could well need to use // This is a random abstract example, but can provide a minimal code repro if necessary
type RenderPropParams = {
// this triggers `react/no-unused-prop-types`
foo: number;
bar: number;
}
const ParentComponent = () => {
const [baz, setBaz] = useState(false);
const childRenderProp = useCallback(
({ foo, bar }: RenderPropParams) => <SomeOtherComponent foo={foo} bar={bar} baz={baz} />,
[baz],
);
return <ChildComponent renderProp={childRenderProp} />;
}; The kind of ugly workaround is this: type RenderPropParams = {
// this triggers `react/no-unused-prop-types`
foo: number;
bar: number;
}
const ParentComponent = () => {
const [baz, setBaz] = useState(false);
const childRenderProp = useMemo(
() =>
({ foo, bar }: RenderPropParams) => (
<SomeOtherComponent foo={foo} bar={bar} baz={baz} />
),
[baz],
);
return <ChildComponent renderProp={childRenderProp} />;
};
}; |
@baseten better would be to define a component at module level, and take the |
Would you mind giving an example? Part of the problem in our case is that |
ahh i see what you mean. because it's forced to take a render prop, you indeed need to do what you're doing there. However, since the useMemo argument is just a render prop, not a component, this plugin shouldn't be checking RenderPropParams at all. I'll reopen this; @baseten, a PR with a failing test case would be most helpful. |
In the
I'll see what I can do 👍 |
It shouldn't warn with useCallback either, since that's not a component. |
👋
A similar issue has been reported and got fixed. I stumbled across a variation of #2689 that still does not seem to work.
Versions
eslint 7.22.0
eslint-plugin-react 7.21.5
The text was updated successfully, but these errors were encountered: