Adding Property Initializers To Your React/Babel For Cleaner Components

Posted about 10 months ago

If you want to declare state like below without the use of a constructor


state = {
    name: "Chris"
}

You need to add the ES7 feature babel-plugin-transform-class-properties.


yarn add babel-plugin-transform-class-properties


// .babelrc
{
  "plugins": ["transform-class-properties"]
}