Gabotronix
3 months ago

Class or function components in react-native to inject mobx store?

Posted 3 months ago by Gabotronix

I'm new to react-native and trying to set up my app with mobx for state management, when trying to inject rootStore into my HomeScreen component I get the following error:

Error: C:\xampp\htdocs\second-try\screens\HomeScreen.js: Leading decorators must be attached to a class declaration

This is my component, as you see I'm suing function based component and I get a warning, but how can I use components ass Class and inject mobx stre into my react-native component.

My HomeScreen file:

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;

Please sign in or create an account to participate in this conversation.