-
-
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
no-unused-prop-types sometimes fails to detect props in functions on stateless components #885
Comments
cc @oliviakim95 |
this bug also triggers when use const PagingBlock = function(props) {
return (
<SomeChild {...props} />
);
};
PagingBlock.propTypes = {
nextPage: React.PropTypes.func.isRequired,
previousPage: React.PropTypes.func.isRequired,
}; The error message is the same. I think we should count all properties as used in this case. |
Agreed. |
Same issue... export default function Content( { post } ) {
const { title, author, body } = post;
return (
<Panel>
<Article
title={ title }
meta={ author }
>
<div dangerouslySetInnerHTML={ { __html: body } } />
</Article>
</Panel>
);
}
Content.propTypes = {
post: PropTypes.shape( {
title: PropTypes.string.isRequired,
author: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
} ),
};
|
const FormInput = (props) => {
const {
input,
type = "text",
...extraProps
} = props;
return (
<div id={input.name + "_view"}>
<input type={type} id={input.name} {...input} {...extraProps}/>
</div>
);
};
FormInput.propTypes = {
input: React.PropTypes.object.isRequired,
required: React.PropTypes.bool,
type: React.PropTypes.string
}; -> complains that |
@xkr47 But it's not, though. How would ESlint know |
I think because |
Agree with @ljharb although it's hard to say how far one should go tracing dependencies here.. |
I have a similar problem with MyComponent.propTypes = {
error: PropTypes.shape({
username: PropTypes.string,
password: PropTypes.string,
}),
} And I pass ESLint throws
|
Probably same issue... import React, { PropTypes } from 'react';
export default function Article(props) {
const {
homepageThumb: {
url: imageUrl,
width: imageWidth,
height: imageHeight
}
} = props;
return (
<img
src={imageUrl}
width={imageWidth}
height={imageHeight}
alt="thumb"
/>
);
}
Article.propTypes = {
homepageThumb: PropTypes.shape({
url: PropTypes.string,
width: PropTypes.number,
height: PropTypes.number
}).isRequired
};
|
I think I've figured out the source of this bug. Looking at @pfhayes example, const PagingBlock = function(props) {
return (
<span>
<a onClick={() => props.previousPage()}/>
<a onClick={() => props.nextPage()}/>
</span>
);
};
PagingBlock.propTypes = {
nextPage: React.PropTypes.func.isRequired,
previousPage: React.PropTypes.func.isRequired,
}; It looks like when Need to find a way to differentiate between the two. I'll submit a PR if I can figure it out. |
Still throws error when:
|
Yeah, for me usage of a prop only in |
You both may want to open another issue for |
@iegik & @ahauser31 - I ran into the same issue and found that if you destructure I also confirmed in this thread: #884 (comment) |
Still getting this in the most recent version of |
@geuis there are tests for the exact same code situation as the original example. If you have a different example that is still failing, would be worth opening a new issue |
Also failing to detect props being used on react lifecycle functions like ...
modalClosed: PropTypes.bool.isRequired componentWillReceiveProps(nextProps) {
if (nextProps.modalClosed) {
this.props.router.goBack()
}
} |
@wellingtonamaralleitao see #1232 |
I might do something wrong but this shows onItemClick propType not to be used:
|
@healqq looks legit. I'd recommend opening a new issue |
export default class Users extends Component {
static propTypes = {
...
onLoad: PropTypes.func.isRequired,
};
async componentWillMount() {
await Promise.all([
this.props.onLoad(),
this.onSearch(),
]);
...
}
...
}
|
Using eslint-plugin-react v^7.14.3 still throw this error |
Experiencing the same issue too. Giving me an error saying 'PropType is defined but prop is never used' when my props is being used within a function inside a functional component. |
I have the same error too, I am passing a prop to a functional component and I define defaultProps so I can make sure it is always a function (it is not required prop) and it marks it as unused |
I have the same error too with eslint-plugin-react v^7.19.0 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
What am I doing wrong? |
@shashwata27 theres no component in that code. Please file a new issue if you’re still having trouble. |
Check I updated the code above, should I make new issue? |
Yes please; commenting on old closed issues is not an efficient way to get help. |
Here is a minimal example that triggers this:
The error message is:
Notes:
<a/>
tag produces the correct lint error, the false error only occurs when both are presentnextPage
andpreviousPage
inside the render function will make the error text saynextPage
is defined but not usedThe text was updated successfully, but these errors were encountered: