0
<script type="text/babel">
    class List extends React.Component {
        state = {
            objects: ['1', '2', '3']
        };
        render() {
            return(<div> objects[1] </div>)
        }
    }

Error: browser.min.js:41 Uncaught SyntaxError: embedded: Unexpected token (4:18)

  2 |         class List extends React.Component {
  3 | 
> 4 |             state = {
    |                   ^
  5 |                 objects: ['1', '2', '3']
  6 |             };

I can't understand((

  • you cannot declare instance variables directly in es6. Refer to link http://stackoverflow.com/questions/22528967/es6-class-variable-alternatives?answertab=votes#tab-top – vijay Nov 14 '16 at 13:05

1 Answers1

0
<script type="text/babel">
    class List extends React.Component {
        constructor(props) {
            this.state = {
                objects: ['1', '2', '3']
            };
        }
        render() {
            return(<div> {this.state.objects[1]} </div>)
        }
    }
Ji aSH
  • 3,206
  • 1
  • 10
  • 18