【问题标题】:Is there any ways to use react navigation props as a define object in reusable component?有没有办法将反应导航道具用作可重用组件中的定义对象?
【发布时间】:2022-01-12 01:50:54
【问题描述】:

我这周开始使用 rn 为一些补习学校制作一个中等规模的应用程序。并发现使用定义的道具导航存在一些问题。

如你所见,我在根 app.js 中使用“test1”、“test2”定义堆栈屏幕名称,与地址变量相同。

问题是当我使用 'test1' 而不是 {address} 时它工作正常,但是当我使用 {address} 时,它对我大喊大叫,即使我控制台它仍然是 'test1'。

这是我的代码:

....
....

    <Stack.Screen name="test1" component={GrLesson1} />
    <Stack.Screen name="test2" component={GrLesson2} />

    function GrHome({navigation}) {
        return (
    <View>
    
    <GrHomeProps title="test1" address="test1" navigation={navigation}/>
    <GrHomeProps title="test2" address="test2" navigation={navigation}/>
    
    </View>
        )
    }


function GrHomeProps({title,navigation,address}) {
    return (
<View>
<TouchableOpacity
onPress={()=>{
navigation.navigate({address})

}}
>

   <Text> {title} </Text>
</TouchableOpacity>
</View>
    )
}

Can somebody help me? find the mistake i made or teach me another way to do this with reusable component?

【问题讨论】:

    标签: javascript reactjs react-native


    【解决方案1】:

    没有大括号

    navigation.navigate(address)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-01
      • 2020-04-07
      • 2021-06-13
      • 1970-01-01
      • 2020-12-17
      • 2020-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多