将功能传递给导航组件

时间:2020-05-16 14:45:20

标签: javascript reactjs react-native

我有一个与本机导航有关的问题

const Swipe = ({signUp}) => {
    const Stack= createStackNavigator()
    return(
        <NavigationContainer>
            <Stack.Navigator screenOptions= {{headerBackTitleStyle:{color:'white'}}}>

                <Stack.Screen name="SignUp" options={
                    {
                        headerStyle: {
                            backgroundColor: Color.Primary
                        },
                    }
                }>
                   {
                       ()=>(
                           <SignUp signUp={signUp}/>
                       )
                   }
                     </Stack.Screen>
                <Stack.Screen name="SignIn" component={SignIn}  options= {
                  ({navigation, route})=> ({
                      HeaderTitle: ()=> route.params.name,
                      headerStyle: {
                          backgroundColor: Color.Primary
                      }
                  })
                }/>
            </Stack.Navigator>
        </NavigationContainer>
    )
}
export default Swipe

in the root app:
<Swipe signUp= {signUp}/>

问题是我何时将signUp函数传递给导航 它可以正常工作,但是当我导航到signIn组件时,它表明导航错误是未定义的对象

有人可以帮助我

1 个答案:

答案 0 :(得分:0)

是否可能没有将登录组件作为道具提供?像:

const Swipe = ({signUp, signIn}) => {
 const Stack= createStackNavigator()
  return(........)
})