-
-
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-state using functional setState #1484
Comments
Can you share the error, and your eslint config? |
Same here. onTitleChange = (title) => {
this.setState({ title, titleChanged: true });
}
onTemplateChange = (template) => {
this.props.navigator.pop();
this.setState((state => ({
template,
title: state.titleChanged ? state.title : getTemplateTitle(template),
})));
};
I'm using |
Your eslint config must be different, because the airbnb config does not permit class properties to be used. |
I'm also using |
@cristianfraser same question; can you share your code and your eslint config? Again, if you're using class properties, you're violating the airbnb style guide, so if you are, you must be using a modified eslint config. |
{
"parser": "babel-eslint",
"extends": [
"airbnb"
],
"env": {
"mocha": true
},
"rules": {
"no-restricted-properties": "off",
"complexity": [ "error", 10 ],
"max-depth": [ "error", 4 ],
"max-nested-callbacks": [ "error", 2 ],
"max-params": [ "error", 4 ],
"max-statements": [ "error", 18 ],
"no-constant-condition": "off",
"no-plusplus": "off",
"no-warning-comments": "error",
"comma-dangle": [
"error",
{
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "always-multiline"
}
],
"no-restricted-globals": "off",
"react/require-default-props": "off",
"react/no-unused-prop-types": "off",
"react/jsx-filename-extension": [
"warn",
{
"extensions": [".js"]
}
],
"react/jsx-no-bind": [
"error",
{
"ignoreRefs": false,
"allowArrowFunctions": false,
"allowBind": false
}
],
"react/no-typos": "off",
"import/no-named-as-default": "off",
"import/prefer-default-export": "off",
"jsx-a11y/href-no-hash": "off",
"jsx-a11y/anchor-is-valid": "off",
"react-native/split-platform-components": "off",
"react-native/no-unused-styles": "error",
"react-native/no-inline-styles": "error",
"react-native/no-color-literals": "error"
},
"globals": {
"__DEV__": true,
"fetch": true,
"ErrorUtils": true
},
"plugins": [
"react-native"
]
}
|
This is a minimal code that shows
This is my eslint config:
Also, I've used class properties with plain |
@cristianfraser you can only use it with |
What do you mean by I can only use it with |
@cristianfraser eslint core doesn't support parsing class properties; only What's happening seems like a bug in the |
Fixed with #1411 |
I'm having a same problem with latest verstion.
I'm using |
Try making onUpdate a constructor-bound instance method (putting arrow functions in class properties is a bad practice) and it should pick it up. |
I've changed it like this. But it shows me the same error... |
Thanks - could you file a new issue with both code examples (the class field and the instance method)? |
sure! |
I meet the same error. Here is my minimal code: import React from 'react';
class Test extends React.Component {
static Sub({ state }) {
const { property } = state;
return <p>{property}</p>;
}
state = {
property: 1 // Unused state field 'property'
}
render() {
return <Test.Sub state={this.state} />;
}
}
export default Test; And it is same when I use constructor style. I am using the latest eslint and etc. |
@mytharcher it’s an antipattern to pass around the entire props or state objects; and it basically prevents any form of static analysis on it. Destructure it first, and explicitly pass the members you need. |
This code:
But eslint shows error for
foo
,no-unused-state
is displayed, but it is being used.The text was updated successfully, but these errors were encountered: