Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.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 变量名中的问号_Javascript_Reactjs - Fatal编程技术网

Javascript 变量名中的问号

Javascript 变量名中的问号,javascript,reactjs,Javascript,Reactjs,在React custom hook中,我们以下面的方式返回ordernumber,变量receive?.order?.id后面的问号在React中是什么意思 export const useTest = props => { ... return { orderTestNumber: receipt?.test?.id }; } 它被称为可选链接(?) 当引用或函数可能未定义或为空时,可选的链接操作符提供了一种简化通过连接对象访问值的方法 它被称为“可选链接操作符”

在React custom hook中,我们以下面的方式返回ordernumber,变量
receive?.order?.id
后面的问号在React中是什么意思

export const useTest = props => {
  ...
  return {
    orderTestNumber: receipt?.test?.id
  };
}

它被称为可选链接(?)

当引用或函数可能未定义或为空时,可选的链接操作符提供了一种简化通过连接对象访问值的方法


它被称为“可选链接操作符”。这就是它的工作原理;如果引用的是深度嵌套的属性,则不会验证所有引用。因此,在缺少引用的情况下,它不会抛出错误,而是返回undefined。