oei
oei

Reputation: 571

How to enable support for class properties in the latest version BabelJS?

Does anyone know how to enable support for properties of a class in the latest version BabelJS?

import React from 'react';
import {Component} from 'react';

export default class Button extends Component {
    constructor(){
        super();
    }

    myProp = {}; //  ERROR: /path/to/file/Button.jsx: Unexpected token (9:11)

    render(){
        return <div></div>;
    }
}

Upvotes: 0

Views: 373

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074979

With Babel 6, you use the syntax-class-properties plugin, by installing it:

npm install babel-plugin-syntax-class-properties

and adding it to your .babelrc:

{
  "plugins": ["syntax-class-properties"]
}

Upvotes: 2

Related Questions