如何使用Mobx在本机中解决此错误?

问题描述 投票:0回答:1

我正在尝试使用Mobx来组织React Native App中的所有状态,但是我在下面的商店中收到了“无法读取属性”绑定“null”的错误。

import { observable } from 'mobx';

class RestaurantStore {
 @observable
 name = 'コンビニ屋';

 @observable
 tag = 'ショッピング';

 @observable
 shortDescription = '$10以上のお買い上げでスタンプ1個';
}

export default RestaurantStore;

请问你能帮帮我吗。

要在下面添加我的package.json。

 "dependencies": {
 "@babel/plugin-proposal-class-properties": "^7.3.4",
 "@babel/plugin-transform-flow-strip-types": "^7.3.4",
 "@expo/vector-icons": "^9.0.0",
 "expo": "^32.0.0",
 "firebase": "^5.8.1",
 "mobx": "^5.8.0",
 "mobx-react": "^5.4.3",
 "react": "16.5.0",
 "react-native": "https://github.com/expo/react-native/archive/sdk-    
  32.0.0.tar.gz",
 "react-native-maps": "^0.23.0",
 "react-native-modal": "^7.0.2",
 "react-native-vector-icons": "^6.1.0",
 "react-navigation": "^3.0.9"
},
 "devDependencies": {
 "@babel/plugin-proposal-decorators": "^7.3.0",
 "babel-eslint": "^10.0.1",
 "babel-preset-expo": "^5.0.0",
 "babel-preset-react-native": "^4.0.1",
 "directory": "^0.1.0",
 "eslint": "^5.12.0",
 "eslint-config-airbnb": "^17.1.0",
 "eslint-plugin-import": "^2.14.0",
 "eslint-plugin-jsx-a11y": "^6.1.2",
 "eslint-plugin-react": "^7.12.3",
 "metro-react-native-babel-preset": "^0.53.0"
},
reactjs react-native expo mobx
1个回答
0
投票

试试这种格式

import { observable, action, computed, toJS , decorate} from "mobx";

class RestaurantStore{
  name = 'コンビニ屋';
  tag = 'ショッピング';
  shortDescription = '$10以上のお買い上げでスタンプ1個';
}

export default decorate(RestaurantStore, {
  name: observable,
  tag: observable,
  shortDescription: observable
});
© www.soinside.com 2019 - 2024. All rights reserved.