Expected property shorthand

Viewed 1393

I'm new to this and facing this error and not too sure what it means.

Error: Expected property shorthand at tree: tree - Triggered by eslint?

import {
  tree, tree1, tree2, tree3, tree4,
} from './Tree';

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      tree: tree,
      downloadingChart: false,
      config: {},
      // highlightPostNumbers: [1],
    };
  }

3 Answers

ESLint wants you to use shorthand in the state object:

    this.state = {
      tree,
      downloadingChart: false,
      config: {},
      // highlightPostNumbers: [1],
    };

You don't have to declare the key and value if the variable you reference is the same name as the key you're defining. You can also deactivate this with ESLint's object shorthand rules.

When the name of key is same as the value. You can write it once as shorthand.

this.state = {
  tree,
};

If your state property tree is same name as imported value tree, just try this.state = {tree} without second one.

Related