简体   繁体   English

如何将 props 传输到位于堆栈中的组件 react native?

[英]How can I transfer props to components located in stack react native?

So here I have a stack:所以这里我有一个堆栈:

const GoBackStack = () => {
    return (
        <Stack.Navigator headerMode="none">
            <Stack.Screen name="GoBack" component={GoBack} />
        </Stack.Navigator>
    )
}

What I need to do is to transfer this GoBack component with props like that: <GoBack any={any} /> .我需要做的是使用这样的道具传输这个 GoBack 组件: <GoBack any={any} /> How can I do so in React Native?我如何在 React Native 中这样做?

You can wrap the desired component with another function?您可以用另一个 function 包装所需的组件吗?

const GoBackStack = () => {

    const GoBackWrapper = (props) => <GoBack { ...props } any={any} />

    return (
        <Stack.Navigator headerMode="none">
            <Stack.Screen name="GoBack" component={GoBackWrapper} />
        </Stack.Navigator>
    )
}

At least, that's how I do it.至少,我是这样做的。 GoBackWrapper needs to be in a closure of GoBackStack if the props that you want to pass depends on GoBackStack's state, otherwise it can be outside of the block.如果要传递的道具取决于 GoBackStack 的 state,GoBackWrapper 需要在 GoBackStack 的闭包中,否则它可以在块之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM