Я новичок в React.Я создаю пользовательскую навигацию по ящикам с помощью DrawerNavigator.Я хотел получить список категорий из API и добавить список меню с параметром cat_id.Каждая категория будет переходить на одну и ту же страницу / экран, но параметр будет использоваться для получения списка результатов.
Я попытался создать массив для DrawerNavigator, но он не получает его, поскольку его нет в компоненте.
export default class App extends Component {
componentDidMount() {
global.dState=0;
global.dynamicData = ["Cats", "Dogs", "Lions"]
return fetch('http://xxxx.com/Api.php?action=category')
.then((response) => response.json())
.then((responseJson) => {
this.dataSource = responseJson
})
}
render() {
return (
<MyApp authed={this.state.ddata} />
)
}
}
const CustomDrawerContentComponent = (props) => (
<Container>
<Header style={styles.drawerHeader}>
<Body>
<Image
style={styles.drawerImage}
source={require('./assets/DrawerIcons/Logo.png')} />
</Body>
</Header>
<Content>
<DrawerItems {...props} />
</Content>
</Container>
);
const MyApp = DrawerNavigator({
//// Below list will come from API
Home: {
screen: HomeScreen,
navigationOptions: ({ navigation }) => ({
title: 'Home'
})
},
Settings: {
screen: SettingsScreen,
navigationOptions: ({ navigation }) => ({
drawerLabel: () => null
})
}
},
{
initialRouteName: 'Home',
drawerPosition: 'left',
contentComponent: CustomDrawerContentComponent,
drawerOpenRoute: 'DrawerOpen',
drawerCloseRoute: 'DrawerClose',
drawerToggleRoute: 'DrawerToggle'
});
Home: {
screen: HomeScreen,
navigationOptions: ({ navigation }) => ({
title: 'Home'
})
},
Settings: {
screen: SettingsScreen,
navigationOptions: ({ navigation }) => ({
drawerLabel: () => null
})
}