0

I'm getting an eslint error on this ES6 declaration of a class variable. Can someone suggest either a better syntax, or what eslint rule I need to add or change.

error: ESLint: Parsing error: Unexpected token =

export default class ErrorBoundary extends React.Component {
  state = { hasError: false, error: null };
  updateHasErrorsToFalse = () => {
    this.setState((prevState) => ({
      hasError: false,
    }));
  }; ...

Here is my .eslintrc.json

{
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "plugins": ["react-hooks"],
  "rules": {
    "semi": [2, "always"],
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "error"
  }
}
Peter Kellner
  • 14,748
  • 25
  • 102
  • 188
  • It's not an ES6 class if it uses class fields – Bergi Jan 16 '22 at 18:35
  • this is the correct answer that solves my issue above. Not the one referencd. https://stackoverflow.com/questions/60046847/eslint-does-not-allow-static-class-properties – Peter Kellner Jan 16 '22 at 18:51

0 Answers0