React Navigation, Issue finding files

Viewed 74

Im brand new to React Native and am struggling with something basic, Trying to divide my app into different files (new file per screen) but my navigator cant find the screens or something. Im 90% sure its a pretty basic mistake but have been stuck on it for an embarrassing amount of time.

Here's the Error:

'' Couldn't find a 'component','getComponent' or 'children prop" for screen 'details'

Im pretty sure I did my import/export correctly but obviously something is wrong.

Code:

//component import (app.js)

import { DetailScreen } from './screens/2nd';
...
...

//stack(app.js)

export default function App() {

  return (
    <NavigationContainer>
      <Stack.Navigator initialRouteName='home'>
        <Stack.Screen name='home' component={HomeScreen} />
        <Stack.Screen name='details' component={DetailScreen} />

      </Stack.Navigator>
    </NavigationContainer>
  );
}



//details page (2nd.js):

const DetailScreen = () => {
    return (
        <View>
            <Text>
                Detail Screen
        </Text>
        </View>
    )
}

export default DetailScreen;
2 Answers

When you declare export default FunctionName you just can call that using import aliasFunction from './yourfile'. But if you want to use import {DetailScreen} ... you need declare export FunctionName at ./screens/2nd

Related