Option 1: Using decorators with CRA v2
If you refer to Mobx documentation, you can get Mobx decorators to work with CRAv2 by using Typescript:
Decorators are only supported out of the box when using TypeScript in create-react-app@^2.1.1.
However, in some cases, you might still face issues when using Mobx with other react frameworks. In that case:
Option 2: Don't use decorators
A detailed step by step guide is documented here.
If you previously defined your observer react component as:
@observer
export default class MyComponent extends React.Component
Change it to:
const MyComponent = observer(class MyComponent extends React.Component{
/* ... */
});
export default MyComponent;
If you previously had:
@observable myElement = null;
You need to change it to:
myElement;
then:
decorate(MyComponent, {
myElement: observable,
})
Hope this helps!