Unexpected token after const

In React, an unexpected marker error occurs when I try to specify a constant, and I cannot understand why.

My code is pretty simple, and I almost exactly followed the bootstrap reaction examples here .

My code is as follows:

import { Component, PropTypes } from 'react';

var rbs = require('react-bootstrap'),
Panel = rbs.Panel;

export default class ResumeSection extends Component {
  constructor(...args) {
    super(...args);
    this.state = {
      open: true
    };
  }

  const title = (
    <h3>Panel title</h3>
  );

  render() {
    return (
      <Panel collapsible expanded={this.state.open}>
        <p>Body</p>
      </Panel>
    );
  }
}

The error occurs titleimmediately after constand just saysSyntaxError: Unexpected Token

+4
source share
1 answer

You cannot define const in this class; it should be transferred to the method.

render() {
  const title = (
    <h3>Panel title</h3>
  );
  // ...
}
+7
source

Source: https://habr.com/ru/post/1624363/


All Articles