6

I'm trying to use mobx with react native and stuck into a problem.

@inject('someStore')
@observer
export class SomeComponent extends Component {
   render() {
       ...
   }
}

I'm sure I configured properly babel plugins for decorator but @inject decorator gives me an exception "Expected a constructor.".

enter image description here

I have no idea why this happen since I had used mobx in this way in an other project. Does anyone had been through this issue?

jesuisgenial
  • 599
  • 4
  • 13

3 Answers3

3

I downgraded the mobx-react version to 5.4.4 and I can confirm that it works.

Try to downgrade mobx-react.

yarn add mobx-react@5.4.4
Rich Michaels
  • 1,540
  • 2
  • 10
  • 18
bkm412
  • 907
  • 2
  • 10
1

Rewriting the class as below worked for me

"mobx": "^5.13.0","mobx-react": "^6.1.3"

class LoginScreen extends React.Component {

}

export default inject("userStore")(observer(LoginScreen));
SkyTreasure
  • 755
  • 1
  • 9
  • 20
1

"mobx-react": "^6.1.3" it works for me

import React, { Component } from 'react';
import {observer, inject} from 'mobx-react';

class SomeComponent extends Component {
class_content
}

export default inject('someStore', 'someStore' /* here you can add as many store files as you need */)(observer(SomeComponent));

But don't forget to add Provider to your App.js or which is your main file

crazycoder
  • 11
  • 4