I have a requirement to make a multi-level drawer menu for an app using React Native. I can customize the drawer by using a CustomDrawerContent. Within this i want to display a subset of the routes. Currently i am making a copy of the props and changing the state.routes variable within it. Is there a better way of doing this?
const Drawer = createDrawerNavigator();
function CustomDrawerContent(props) {
const prop2 = props;
prop2.state.routes = prop2.state.routes.slice(0, 3);
return (
<DrawerContentScrollView {...props} contentContainerStyle={{ flex: 1 }}>
<View style={styles.drawerMenu}>
<DrawerItemList {...prop2} />
</View>
</DrawerContentScrollView>
);
}
export default function () {
return (
<Drawer.Navigator initialRouteName="Home_Home" hideStatusBar={true} statusBarAnimation="fade"
drawerContent={(props) => <CustomDrawerContent {...props} />}>
<Drawer.Screen name="Home_Home" component={HomeStack} />
<Drawer.Screen name="Home_About" component={HomeStack} />
<Drawer.Screen name="Home_FAQ" component={HomeStack} />
<Drawer.Screen name="Profile_Calendar" component={HomeStack} />
<Drawer.Screen name="Profile_Subscription" component={HomeStack} />
</Drawer.Navigator>
);
}
I have tried passing in state as a props but that doesnt seem to pick it up.