Javascript 在react native to Injection store中的类或函数组件?
我对react native很陌生,尝试使用mobx设置我的应用程序以进行状态管理,当尝试将rootStore注入我的主屏幕组件时,我遇到以下错误:Javascript 在react native to Injection store中的类或函数组件?,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我对react native很陌生,尝试使用mobx设置我的应用程序以进行状态管理,当尝试将rootStore注入我的主屏幕组件时,我遇到以下错误: Error: C:\xampp\htdocs\second-try\screens\HomeScreen.js: Leading decorators must be attached to a class declaration 这是我的组件,正如你们所看到的,我正在起诉基于函数的组件,我得到了一个警告,但我如何使用组件ass类并将mobx s
Error: C:\xampp\htdocs\second-try\screens\HomeScreen.js: Leading decorators must be attached to a class declaration
这是我的组件,正如你们所看到的,我正在起诉基于函数的组件,我得到了一个警告,但我如何使用组件ass类并将mobx stre注入到我的react本机组件中呢
我的主屏幕文件:
import * as React from 'react';
import { StatusBar } from 'expo-status-bar';
import { View, Text, StyleSheet } from 'react-native';
@inject(stores => ({
postStore: rootStore.postStore,
//authStore: rootStore.authStore,
})
)
//ERROR IS RIGHT
@observer
const HomeScreen = function()
{
return (
<View style={styles.container}>
<Text>{postStore.postMessage}</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default HomeScreen;
import*as React from'React';
从“博览会状态栏”导入{StatusBar};
从“react native”导入{View,Text,StyleSheet};
@注入(存储=>({
邮局:rootStore.postStore,
//authStore:rootStore.authStore,
})
)
//错误是正确的
@观察者
常量主屏幕=函数()
{
返回(
{postStore.postMessage}
);
}
const styles=StyleSheet.create({
容器:{
弹性:1,
背景颜色:“#fff”,
对齐项目:“居中”,
为内容辩护:“中心”,
},
});
导出默认主屏幕;
您是否尝试过const HomeScreen=observer(function(){…}
?我应该在哪里注入存储,如postStore?您是否尝试过const HomeScreen=observer(function(){…}
?我应该在哪里注入存储,如postStore?