繁体   English   中英

具有对象参数的React函数抛出意外令牌

[英]React function with object params throws an unexpected token

我有个问题。 我在React Native中具有以下功能。

const HandleConfirmApplication = async (
  opts: { 
    isInvite: boolean,
    confirmationCheckValues: () => any,
    confirmPopUp: () => any,
    loadingApply: () => any,
    decision: () => any,
    updateState: () => any
  }
) => {
  const { 
    isInvite,
    confirmationCheckValues,
    confirmPopUp,
    loadingApply,
    decision,
    updateState 
  } = opts; //then do stuff

当我尝试调用它时,我这样称呼它:

onConfirm={async () =>
                HandleConfirmApplication({ 
                  opts.isInvite: true,
                  opts.confirmationCheckValues: this.props.confirmationCheckValues,
                  opts.confirmPopUp: this.props.onToggleConfirmPopUp,
                  opts.loadingApply: this.props.onToggleLoadingApply,
                  opts.decision: this.handleShiftInviteDecision('ACCEPT'),
                  opts.updateState: null

                })
              }

如果删除对象并正常调用它们,它将起作用,但是,当我尝试更新对象时,我可以使函数参数成为对象,这会在每行上引发错误,提示意外的标记为',' expected ','

有一个. 属性名称中的无效在JavaScript中无效:

 console.log({ opts.isInvite: 'example' }) 

您应该只传递参数本身:

 HandleConfirmApplication({ isInvite: ..., // ... rest of params }) 


请注意,从技术上讲,您可以使用. 如果将其用引号引起来,则使用属性名称,但这会在您的特定代码中给您带来不正确的行为,因为您没有使用该格式声明任何属性。

 console.log({ 'opts.isInvite': 'this is fine' }) 

暂无
暂无

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

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