A
A
Abr_ya2020-05-28 22:22:07
React
Abr_ya, 2020-05-28 22:22:07

React: arrow function in class, what linter doesn't like?

I use a class to get data on the API, otherwise I try to write everything on functions.
In the class, I process the data a little before returning it to the display.

Here is an example of processing:

transformPerson = (person) => {
    return {
      id: this.getId(person),
      name: person.name,
      gender: person.gender,
      birthYear: person.birthYear,
      eyeColor: person.eyeColor,
    };
  }

ESLint underlines the assignment sign and writes "Unexpected token" (without the error number) in the pop-up window. What does he not like and how can it be fixed?
5ed00f2244de0912149412.jpeg

UPD:
Based on the totality of answers, the issue was resolved as follows:
1) installed the babel-eslint parser:
npm i -D babel-eslint
2) added .eslintrc.json to the linter config:
parser: 'babel-eslint'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2020-05-28
@Abr_ya

This syntax (class properties or something like that) is not yet included in the standard, so the interpreter crashes on this line. IfNT should be configured to handle this syntax. Google class properties eslint setup.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question