对未定义为参数的引用组件属性作出React?

f0ofjuux  于 2023-11-21  发布在  React
关注(0)|答案(1)|浏览(132)
export default function SoftMount({
  children,
  child_ref,
  real_class_name,
  duration,
}) {
  
  return <div/>
}

字符串
使用方法:

<SoftMount unexpected_prop={"some_value"} />


<SoftMount />内部,如何访问unexpected_prop

2guxujil

2guxujil1#

您可以使用“rest参数”sytax(...variable_name)捕获所有剩余的属性

export default function SoftMount({
  children,
  child_ref,
  real_class_name,
  duration,
  ...other_props // This will collect all other props not destructured
}) {
  console.log(other_props.unexpected_prop); // "some_value"

  return <div/>
}

字符串

相关问题