Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在无状态组件中使用react导航将getParam参数传递到另一个屏幕以触发graphql变异?_Javascript_Reactjs_React Native_React Component - Fatal编程技术网

Javascript 如何在无状态组件中使用react导航将getParam参数传递到另一个屏幕以触发graphql变异?

Javascript 如何在无状态组件中使用react导航将getParam参数传递到另一个屏幕以触发graphql变异?,javascript,reactjs,react-native,react-component,Javascript,Reactjs,React Native,React Component,按照以下文档:,我基本上会这样做(家长): 然后传给孩子 class DetailsScreen extends React.Component { render() { const { navigation } = this.props; const itemId = navigation.getParam('itemId', 'NO-ID'); const otherParam = navigation.getParam('otherParam', 'some d

按照以下文档:,我基本上会这样做(家长):

然后传给孩子

class DetailsScreen extends React.Component {
  render() {
    const { navigation } = this.props;
    const itemId = navigation.getParam('itemId', 'NO-ID');
    const otherParam = navigation.getParam('otherParam', 'some default value');

    return ( (..omited for brevity)
编辑: 我的情况是,在一个屏幕/容器中,我们触发了一个graphql变异,它获取一个电话号码并向用户检索代码。 在下一个屏幕上,我需要使用这个用户刚刚插入的电话号码来触发另一个变异,该变异使用电话号码和代码进行身份验证。我不想使用状态来实现这一点,因为react导航上有可用的api

家长:

signInUser(phoneNumber: string) {
  const { navigation, sendCode } = this.props
  sendCode({ variables: { phoneNumber } }) // graphql mutation
  navigation.navigate('Authenticate', { phoneNumber }) // passing 
                                            // phoneNumber as param

}
儿童:

export const AuthenticationCodeModal = (props: NavigationScreenProps) => {
  const {navigation} = props
  const phoneNumber = navigation.getParam(phoneNumber)
  // console.log(phoneNumber)
  // I need to get phoneNumber here and pass it as props to 
  // <AuthenticationFormContainer> which will fire up auth mutation
  return(
    <View style={styles.container} >
      <AuthenticationFormContainer/>
    </View>
  )
}
export const authenticationcodemodel=(道具:NavigationScreenProps)=>{
常量{navigation}=props
const phoneNumber=navigation.getParam(phoneNumber)
//console.log(电话号码)
//我需要在这里得到电话号码,并将其作为道具传递给
//这会激发身份变异
返回(
)
}

如果您对这样的任务使用redux,它会更好、更有趣。Redux有一个可以由任何组件评估的全局状态

结果是getParam接收的值的一个简单语法错误,这样做修复了我的问题:

navigation.navigate('Authenticate', { phoneNumber: {phoneNumber: phoneNumber} })

很抱歉但你能解释一下你想要什么吗?@anhtu抱歉。我想将phoneNumber作为参数传递到另一个屏幕。在一个屏幕上,我们会让用户插入他的电话号码并触发一个变异,向用户发送一个smsCode,在下一个屏幕上,我们需要得到他刚刚插入到上一个屏幕上的这个电话号码,以及用户下一个屏幕的代码,以进行身份验证(需要电话号码和代码)尽管我使用阿波罗链接州作为州管理图书馆,我还是想到了这一点。但是我不认为像这样把东西放在州里是一种好的做法,因为我们有一种更简单的方法来做。。
navigation.navigate('Authenticate', { phoneNumber: {phoneNumber: phoneNumber} })