How to use decorators in create-react-app

To use decorators inside of your create-react-app application, you’ll need to eject. But ejecting doesn’t need to be scary! Quite the contrary. There are three simple steps, and it takes less than a minute.

  1. Eject from create-react-app.
yarn eject
  1. Run the following command to add the Babel plugin for decorator support.
yarn add babel-plugin-transform-decorators-legacy --dev
  1. In package.json, create a babel section and add a plugins array with your new plugin:
{
"name": "example",
"version": "1.0.0",
"babel": {
"plugins": ["transform-decorators-legacy"]
},
...
}

Now, you should be able to use decorators.

And if something went terribly wrong, you can also undo eject.