I get the following error: If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the \'decorators-legacy\' plugin instead of \'dec
Answer are in the official document: https://mobx.js.org/best/decorators.html
you can find many ways to enable it in section "Enabling decorator syntax"
take the Babel 7 for example, create a project using mobx+create-react-app from scratch:
npx create-react-app hello-mobx
//This moves files around and makes your app’s configuration accessible.
npm run eject
npm install --save-dev babel-plugin-transform-decorators-legacy
npm install --save-dev @babel/plugin-proposal-decorators
npm install --save-dev @babel/plugin-proposal-class-properties
edit package.json: package.json:
"babel": {
"plugins":[
[
"@babel/plugin-proposal-decorators",
{
"legacy":true
}
],
[
"@babel/plugin-proposal-class-properties",
{
"loose":true
}
]
],
"presets":[
"react-app"
]
}
install mobx:
npm install mobx --save
npm install mobx-react --save
enjoy!