mobx + react unexpected token
create-react-app does not support decorators (@
). You could either eject create-react-app to add it yourself, set up your own environment from scratch, or use something like mobx-react-boilerplate as your starting point.
I have personally used react-app-rewired with the mobx extension with great success.
You are missing packages after running npm run eject (as create-react-app does not support decorators).
Run npm install --save-dev babel-plugin-transform-decorators-legacy babel-plugin-transform-class-properties
Then add the following Babel configuration to your package.json
"babel": { "plugins": [ "transform-decorators-legacy" ], "presets": [ "react-app" ]},
You could use the syntax provided that doesn't use decorators (here and here).
Here's an example using the App class code you provided:
import React, { Component } from 'react';import { action, extendObservable } from 'mobx'import {observer} from 'mobx-react';class App { constructor() { extendObservable(this, { cake = [], }); }}export default new App();