【发布时间】: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