Jultrem
Jultrem

Reputation: 1

React Native/Expo Error: "Element type is invalid" in App Component

I'm currently working on a React Native app using Expo, where I'm building a broadcast receiver to receive a broadcast from DataWedge.

In my App.js file, I have implemented the broadcast receiver logic as follows:

// Import statements
import * as Broadcast from 'expo-broadcast';

export default function App() {
  const [broadcastContent, setBroadcastContent] = useState(null);

  useEffect(() => {
    // Subscribe to the broadcast event
    const subscription = Broadcast.addListener('test.expo.ACTION', (event) => {
      const content = event.data;
      setBroadcastContent(content);
    });

    return () => {
      // Unsubscribe from the broadcast event when component unmounts
      subscription.remove();
    };
  }, []);

  if (!broadcastContent) {
    return <AppLoading />;
  }

  return (
    <View style={styles.container}>
      <Text>Broadcast Content: {broadcastContent}</Text>
      <StatusBar style="auto" />
    </View>
  );
}

// Styles

However, when attempting to run the app, I encounter the following error message: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

This error occurs specifically in the App component, but I'm having difficulty understanding its cause. I've double-checked my import/export statements, ensured that all dependencies are properly installed, and verified that the component is exported correctly as the default export.

Can someone please provide insights into what might be causing this error or suggestions for alternative libraries instead of 'expo-broadcast' ! Any assistance would be greatly appreciated. Thank you!

Upvotes: 0

Views: 33

Answers (0)

Related Questions