-
-
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
Props inside async functions are not looked up #1583
Comments
Duplicate of #1473 I briefly looked into it and it seems it is related to destructuring within async functions that are defined as class properties. This seems to work: async componentDidMount() {
const { propIsDetected } = this.props
}
async componentDidMount() {
console.log(this.props.propIsDetected)
}
myMethod = async () => {
console.log(this.props.propIsDetected)
} But indeed, the example from the OP is failing: myMethod = async () => {
const { propIsNOTDetected} = this.props
} |
Upon further digging, the issue is because https://github.com/yannickcr/eslint-plugin-react/blob/master/lib/util/Components.js#L650 Therefore, the Not sure what's the proper fix for this. Removing this logic seems scary, but it only fails one test inside var Hello = async (props) => {
return <div>Hello {props.name}</div>;
}: Maybe this logic was added as a quick fix to make this specific case work... not sure... |
I think arrow function class properties should be categorized as non-components. |
I have a related issue. In my static propTypes = {
onToggleShortlist: PropTypes.func.isRequired
}; Which is then used in an async handleToggleShortlist(isShortlisted) {
// ...
const type = // ...
await this.props.onToggleShortlist(type, this.props.model.location.locationId);
// ...
} However when running ESLint I get: onToggleShortlist PropType is defined but prop is never used react/no-unused-prop-types. Without Where package.json is:
|
Updated and all seems to be okay now.
|
@haikyuu please let me know if this is still a problem, and i'll reopen |
I'm still having this issue in an async class method. It's a normal method, e.g.
|
@trisys3 that class doesn't extend |
Sorry, forgot about that. It extends It was just an example, anyway. I can try to see if it actually warns, otherwise I can experiment to see how much is actually needed for breakage. |
If you could file a new issue, with the full component code, installed eslint* versions, and eslint config, that’d be great. |
OK. I'll try to get a simplified test case that doesn't work. |
I have a test case, and will put it on GitHub. From what I can determine, the problem comes from a combination of destructuring and async functions. You need to destructure |
I am having this issue in async functions
This does not show warning missing in props validation. But when i remove async, it works as expected.
The text was updated successfully, but these errors were encountered: