1

i have been trying to make a BottomTabNavigator for my app but has been unable to do so. Kindly help me in identifying error in the code.

This is the code written in App.js

import * as React from 'react';

import  { createBottomTabNavigator }  from '@react-navigation/bottom-tabs';

import mapscreen from './screens/MapScreen';
import groupscreen from './screens/GroupScreen';


import { NavigationContainer } from '@react-navigation/native';

const Tab = createBottomTabNavigator();

export default () => (
         <NavigationContainer>
         
    <Tab.Navigator>

      <Tab.Screen name="map" component={mapscreen}/>

      <Tab.Screen name="group" component={groupscreen} />

      
    </Tab.Navigator>
         </NavigationContainer>
       );

This the code written in MapScreen.js

import * as React from 'react';
import { View, Text,StyleSheet} from 'react-native';

export const mapscreen = () => {

    <View style = {styles.container}>
    <Text>
        Map will exist here!!
    </Text>
    </View>
};



const styles = StyleSheet.create({
    container: {
      flex: 1, 
      alignItems: 'center', 
      justifyContent: 'center',
      

    },
  });

This is the code written in GroupScreen.js

import * as React from 'react';
import { View, Text,StyleSheet} from 'react-native';

export const groupscreen = () => {

    <View style = {styles.container}>
    <Text>
        group exist here!!
    </Text>
    </View>
};


const styles = StyleSheet.create({
    container: {
      flex: 1, 
      alignItems: 'center', 
      justifyContent: 'center',

    },
  });
Ketan Ramteke
  • 10,183
  • 2
  • 21
  • 41
Onkar Mehra
  • 43
  • 1
  • 10

1 Answers1

0

Working App: Expo Snack

There were few syntactical errors, other than that everything was fine.

//App.js
import * as React from 'react';

import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';

import MapsScreen from './screens/MapsScreen';
import GroupScreen from './screens/GroupScreen';

import { NavigationContainer } from '@react-navigation/native';

const Tab = createBottomTabNavigator();

export default App=() => (
  <NavigationContainer>
    <Tab.Navigator>
      <Tab.Screen name="Map" component={MapsScreen} />
      <Tab.Screen name="Group" component={GroupScreen} />
    </Tab.Navigator>
  </NavigationContainer>
);
//MapsScreen.js
import * as React from 'react';
import { View, Text, StyleSheet } from 'react-native';

export default  MapsScreen = ({navigation}) => {
  return <View style={styles.container}>
    <Text>Map will exist here!!</Text>
  </View>;
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
});
//GroupScreen.js
import * as React from 'react';
import { View, Text, StyleSheet } from 'react-native';

export default GroupScreen = ({navigation}) => {
  return <View style={styles.container}>
    <Text>group exist here!!</Text>
  </View>;
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
});
Ketan Ramteke
  • 10,183
  • 2
  • 21
  • 41
  • I ran your suggested code on my editor. It didn't work out and showed errors. I have mentioned the errors in the next comment. – Onkar Mehra Mar 05 '21 at 14:54
  • ERROR 20:19 Building JavaScript bundle: error ERROR 20:19 Unable to resolve module ./screens/MapsScreen from C:\Users\Ind\Desktop\webdev\Onkar\App.js: – Onkar Mehra Mar 05 '21 at 15:04
  • None of these files exist: * screens\MapsScreen(.native|.ios.expo.ts|.native.expo.ts|.expo.ts|.ios.expo.tsx|.native.expo.tsx|.expo.tsx|.ios.expo.js|.native.expo.js|.expo.js|.ios.expo.jsx|.native.expo.jsx|.expo.jsx|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json) * – Onkar Mehra Mar 05 '21 at 15:05
  • screens\MapsScreen\index(.native|.ios.expo.ts|.native.expo.ts|.expo.ts|.ios.expo.tsx|.native.expo.tsx|.expo.tsx|.ios.expo.js|.native.expo.js|.expo.js|.ios.expo.jsx|.native.expo.jsx|.expo.jsx|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json) – Onkar Mehra Mar 05 '21 at 15:06
  • 3 | import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; 4 | > 5 | import MapsScreen from './screens/MapsScreen'; | ^ 6 | import GroupScreen from './screens/GroupScreen'; 7 | 8 | import { NavigationContainer } from '@react-navigation/native'; – Onkar Mehra Mar 05 '21 at 15:06
  • I don't know how you set up the project but the code I have posted is tested and you can see the working demo app link in the answer which is working without error. – Ketan Ramteke Mar 05 '21 at 15:17