React es7 static childContextTypes unexpected token

I am still reacting very recently, and still learning with es7.

I have a problem:

import React from 'react'; import MessageList from './MessageList.jsx'; import mui from 'material-ui'; var ThemeManager = new mui.Styles.ThemeManager(); var Colors = mui.Styles.Colors; var AppBar = mui.AppBar; class App extends React.Component { constructor(){ super(); ThemeManager.setPalette({ primary1Color: Colors.blue500, primary2Color: Colors.blue700, primary3Color: Colors.blue100, accent1Color: Colors.pink400 }); } static childContextTypes = { muiTheme: React.PropTypes.object } getChildContext(){ return { muiTheme: ThemeManager.getCurrentTheme() }; } render() { return( <div> <AppBar title="Awesome" /> <MessageList /> </div> ); } } export default App; 

when i tried to compile using webpack-dev-server it returns me an error

 Module build failed: SyntaxError: D:/learn/react2/src/components/App.jsx: Unexpected token (21:27) } static childContextTypes = { ^ muiTheme: React.PropTypes.object } 

I will compile it using babel with

 "presets": ["react", "es2015"] 

What should I do to make it work?

I am using the latest reaction (0.14.4).

thanks

+2
source share
1 answer

Like Babel 6, you need the transform-class-properties plugin to support class properties.

+2
source

All Articles