首页 > 解决方案 > 有没有办法在解构后获得论点?

问题描述

我试图从 React 的功能组件内部获取参数列表。

export function SomeFunction ({ first, second third }){
// do something with the arguments 
  let props = this.arguments;
return <div> hello</div>}

那么在我解构它们之后,有没有办法得到所有的论点?

标签: reactjsreact-functional-component

解决方案


你很接近,你可以使用函数中的参数值。arguments是一个类似数组的对象,并且由于该函数仅使用一个参数,因此您可以访问第零个元素。

function SomeFunction({ first, second, third }) {
  // do something with the arguments
  const props = arguments[0];
  console.log(props);
  return 42;
}

SomeFunction({ first: "1", second: 2, third: "third", fourth: "4th" });


推荐阅读