8329

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

Question:

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>; } }

Answer1:

With Babel 6, you use the <a href="http://babeljs.io/docs/plugins/syntax-class-properties/" rel="nofollow">syntax-class-properties plugin</a>, by installing it:

npm install babel-plugin-syntax-class-properties

and adding it to your .babelrc:

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

Recommend

  • Jackson handling of remaining fields
  • Doxygen not properly recognizing properties
  • How to give @PropertyResource precedence over any other application.properties in Spring?
  • GORM Mapping two attributes of same Class with hasMany
  • Deploying pre-encrypted configuration files to a production environment
  • Instanciate service on startup in Angular2
  • get passwords from chrome
  • Spring boot 2.0.0.M4 required a bean named 'entityManagerFactory' that could not be found
  • Creating Java object from class name with constructor, which contains parameters [duplicate]
  • how to avoid repetitive constructor in children
  • How can I set a binding to a Combox in a UserControl?
  • How can I enlarge video fullscreen without the affected interface project in as3?
  • Create DicomImage from scratch using Dcmtk
  • Typescript - Unable to get 'import' statement to function
  • Android fill_parent issue
  • Highlight and Bold text in JTextPane
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • how to do an event when i swipe from fragment to the other
  • Deleting and Updating values from a cusrsor adapter
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Spray.io: When (not) to use non-blocking route handling?
  • Possible to stop flickering java tooltip in heavyweight mode?
  • Updating server-side rendering client-side
  • script to move all files from one location to another location
  • Modifying destination and filename of gulp-svg-sprite
  • ILMerge & Keep Assembly Name
  • Symfony2: How to get request parameter
  • jquery mobile loadPage not working
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • Akka Routing: Reply's send to router ends up as dead letters
  • GridView Sorting works once only
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Hits per day in Google Big Query
  • Angular 2 constructor injection vs direct access
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Linking SubReports Without LinkChild/LinkMaster
  • unknown Exception android
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Observable and ngFor in Angular 2