如何在 react native 中获取在屏幕之间传递的数据的标题?



父类

this.props.navigation.navigate('Child', {
something: 'Some Value',
});

儿童班

this.props.navigation.state.params.something // outputs "Some Value"

但我想得到"某物"作为String,以便在 if 语句中进行比较。 我应该怎么做?

如果你想访问所有导航参数名称,你可以做const paramNames = Object.keys(this.props.navigation.state.params)这将是一个像['something', 'anotherParam', 'andAnotherParam']这样的数组。如果只传递了一个参数,则可以分别使用paramNames[0]获取其名称

最新更新