现在我正在尝试使用本机,Mobx和Expo做出反应。
但是,在我安装了Mobx并使用Mobx的observable制作Store后,我收到如下错误。
除了我提到的这些信息,我还使用了一些像@observer和@inject,Provider这样的装饰器。
使用Provider添加我的组件代码。
import React from "react";
import { View, StyleSheet } from "react-native";
import { Provider } from "mobx-react/native";
import HomeHeader from "../Elements/Home/HomeHeader";
import HomeShopList from "../Elements/Home/HomeShopList";
import HomeAllCouponListButton from "../Elements/Home/HomeAllCouponListButton";
import HomeAllShopListButton from "../Elements/Home/HomeAllShopListButton";
import RestaurantStore from "../Stores/EachStores/RestaurantStore";
class Home extends React.Component {
render() {
const { navigation } = this.props;
return (
<View style={styles.container}>
<HomeHeader />
<Provider restaurantStore={RestaurantStore}>
<HomeShopList navigation={navigation} />
</Provider>
<HomeAllCouponListButton />
<HomeAllShopListButton />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
}
});
您的提供商商店必须正确配置:
应该是这样的。
<Provider restaurantStore={RestaurantStore}>
而不是像下面:
<Provider store={RestaurantStore}>
请参考here
另外,尝试更改import语句
import RestaurantStore from "../Stores/EachStores/RestaurantStore";
至 :
import { RestaurantStore} from "../Stores/EachStores/RestaurantStore";