Reputation: 725
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."
.
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?
Upvotes: 6
Views: 1446
Reputation: 39
"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
Upvotes: 1
Reputation: 884
Rewriting the class as below worked for me
class LoginScreen extends React.Component {
}
export default inject("userStore")(observer(LoginScreen));
Upvotes: 1
Reputation: 1057
I downgraded the mobx-react version to 5.4.4 and I can confirm that it works.
Try to downgrade mobx-react.
yarn add [email protected]
Upvotes: 3