У меня есть тег String name, и я передал его из компонента 'Main' в компонент 'Details' с помощью реквизита и хочу использовать эту строку тега для использования в функции рендеринга таких деталей, как
Попробовал это вфункция рендеринга 'Details', не работает
render() {
const Tagname = this.props.navigation.getParam('component', 'Component Does not exist')
return (
<Container>
<Tagname/>
</Container>
)
}
Значение const Tagname
равно Basic
(консоль зарегистрирована), и у меня есть компонент, созданный и импортированный правильно с именем Basic
Вот основной:
import React, { Component } from "react";
import { View, Text, Button } from 'react-native';
export default class Main extends Component {
render() {
<View>
<Text
style={styles.texts}
onPress={()=> {
this.props.navigation.navigate('Details', {
component: 'Basic'
})
}}
>
{elem}
</Text>
</View>
}
}
Маршрутизатор:
import React from 'react';
import { createAppContainer, createStackNavigator, StackActions, NavigationActions } from 'react-navigation';
import Details from './Details'
import Main from './Main'
const AppNavigator = createStackNavigator({
Home: {
screen: Main,
},
Details: {
screen: Details,
},
}, {
initialRouteName: 'Home',
});
export default createAppContainer(AppNavigator);
Подробности:
import React, { Component } from 'react';
import { View, Text, Button } from 'react-native';
import Basic from './Basic.js'
export default class Details extends Component {
render() {
const Tagname = this.props.navigation.getParam('component', 'Component Does not exist')
return (
<View>
<Tagname/>
</View>
)
}
}
Базовый:
import React, { Component } from 'react';
import { View, Text, Button } from 'react-native';
export default class Basic extends Component {
render() {
return (
<View>
<Text>Hello world</Text>
</View>
)
}
}