Skip to content

Instantly share code, notes, and snippets.

@Nomeyho
Last active January 13, 2019 16:43
Show Gist options
  • Save Nomeyho/8eb0fc9aa068a14ef87cc0da94b6103c to your computer and use it in GitHub Desktop.
Save Nomeyho/8eb0fc9aa068a14ef87cc0da94b6103c to your computer and use it in GitHub Desktop.
React + decorator

React + Decorator

Add decorator support (e.g. Mobx) to a React application created with create-react-app

  1. npm install --save-dev react-app-rewired babel-plugin-transform-decorators-legacy
  2. Replace react-scripts with react-app-rewired in package.json (see below)
  3. Create a new file 'config-overrides.js' at the root of the project (next to node_modules) and copy the content below.

For react-app-rewired < 2.0.1, use https://gist.github.com/imekachi/4edd1d3637bdb02f26c5dc4c371722af

const { addDecoratorsLegacy, override } = require('customize-cra')
module.exports = override(
addDecoratorsLegacy()
)
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test --env=jsdom",
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment