Reactjs 如何使用React Navigation 5捕获参数?

Reactjs 如何使用React Navigation 5捕获参数?,reactjs,react-native,react-navigation,react-navigation-v5,Reactjs,React Native,React Navigation,React Navigation V5,更新:我解决了这个问题,你可以在我发布后的评论中看到。我会继续这样做,以防它对其他人有帮助,或者如果有人有更好的方法或方法 我的目标是将参数传递到下一个屏幕。我将展示我在没有React Navigation 5的情况下是如何做到这一点的,这样您就可以看到我的目标: 我有一个屏幕上的按钮,如下所示: <Button title="View Card" onPress={() => this.props.navigation.navigate(&quo

更新:我解决了这个问题,你可以在我发布后的评论中看到。我会继续这样做,以防它对其他人有帮助,或者如果有人有更好的方法或方法

我的目标是将参数传递到下一个屏幕。我将展示我在没有React Navigation 5的情况下是如何做到这一点的,这样您就可以看到我的目标:

我有一个屏幕上的按钮,如下所示:

<Button
    title="View Card"
    onPress={() => this.props.navigation.navigate("CardDetail", {cardId: 1})}
/>
这似乎很有希望,但我找不到一种方法将其传递到概述中

我已经尝试通过以下方式传递道具:
consttab=createBottomTabNavigator({props})几种方法。要么什么都没有发生,要么它告诉我我的方法在RN5中不被接受

我这样做对了吗

我已经阅读了RN5的文档,并尝试了许多方法来传递参数

那太容易了 第一:当你传递参数CardDetail(现在是tabbar)时,这意味着你的参数是CardDetail的道具

const Tab = createBottomTabNavigator();

class CardDetail extends Component {
    const cardId = this.props.route.params.cardId
    render() {
        return(
             <Tab.Navigator>
                 // ==> and pass cardId into Overview as props
                 <Tab.Screen name="Overview" component={() => <Overview cardId={cardId}/>} />
             </Tab.Navigator>
        );
    }
}
const Tab=createBottomTabNavigator();
类CardDetail扩展组件{
const cardd=this.props.route.params.cardd
render(){
返回(
//==>并将Cardd作为道具传递到概览中
} />
);
}
}
在概览组件中,只需像这样使用cardId即可

function Overview(props) {
    const {cardId} = props;
    return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Overview</Text>
        <Text>{cardId}</Text>
    </View>
  );
}
功能概述(道具){
const{cardId}=props;
返回(
概述
{cardId}
);
}

我能够通过:
{props=>}
而不是使用函数
const Overview=props=>{
如果这个问题有助于其他人或其他人有更有效的方法,那么这个问题就不提了。这是第一次显示组件概述吗?因为可能是以前打开过,现在再次打开时,它只显示以前渲染的部分,而当时可能还没有卸载
function Overview({props}) {
    const cardId = React.useState(this.props.route.params.cardId);
    return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Overview</Text>
        <Text>{cardId}</Text>
    </View>
  );
}
<Tab.Screen name="Overview" component={Overview} options={{ title: this.props.route.params.cardId }} />
            <Tab.Screen name="Overview">
                {props => <Overview {...this.props}  />}
            </Tab.Screen>
const Tab = createBottomTabNavigator();

class CardDetail extends Component {
    const cardId = this.props.route.params.cardId
    render() {
        return(
             <Tab.Navigator>
                 // ==> and pass cardId into Overview as props
                 <Tab.Screen name="Overview" component={() => <Overview cardId={cardId}/>} />
             </Tab.Navigator>
        );
    }
}
function Overview(props) {
    const {cardId} = props;
    return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Overview</Text>
        <Text>{cardId}</Text>
    </View>
  );
}