Semantic-ui-react: fix(Menu): SyntaxError:Unexpected token(6:8)

Created on 17 Oct 2016  路  2Comments  路  Source: Semantic-Org/Semantic-UI-React

import React, { Component } from 'react'
import { Menu, Button } from 'semantic-ui-react'

export default class TopBar extends Component {

  state = { activeItem: 'Home' }

  handleItemClick = (e, { name }) => this.setState({ activeItem: name })

  render() {
    const { activeItem } = this.state
    return (
        <Menu pointing secondary>
          <Menu.Item name='Home' active={this.state === 'Home'} onClick={this.handleItemClick} />
          <Menu.Item name='Projects' active={this.state === 'Projects'} onClick={this.handleItemClick} />
          <Menu.Item name='Tutorials' active={this.state === 'Tutorials'} onClick={this.handleItemClick} />
          <Menu.Menu position='right'>
            <Menu.Item name='logout' active={this.state === 'logout'} onClick={this.handleItemClick} />
          </Menu.Menu>
        </Menu>
    )
  }
}

Steps to Reproduce
I tried to run the example codes but it reported the SyntaxError: Unexpected token(6:8) ,it seems that we can't declare variables in the class.

Expected
It should be passed

Result
The Menu does not do this

Testcase
The docs show the issue: http://react.semantic-ui.com/collections/menu
Fork this to get started: http://codepen.io/levithomason/pen/ZpBaJX

Most helpful comment

I sovled it.
Install the babel plugin:npm install babel-plugin-transform-class-properties,
and add line to the .babelrc file:"plugins": ["transform-class-properties"]
Link:http://babeljs.io/docs/plugins/transform-class-properties/

All 2 comments

I sovled it.
Install the babel plugin:npm install babel-plugin-transform-class-properties,
and add line to the .babelrc file:"plugins": ["transform-class-properties"]
Link:http://babeljs.io/docs/plugins/transform-class-properties/

Thanks for the report. There've been a few people asking for a Webpack setup guide. If we add one, this will come in handy.

Was this page helpful?
0 / 5 - 0 ratings