reactjs - 有没有办法在解构后获得论点?
问题描述
我试图从 React 的功能组件内部获取参数列表。
export function SomeFunction ({ first, second third }){
// do something with the arguments
let props = this.arguments;
return <div> hello</div>}
那么在我解构它们之后,有没有办法得到所有的论点?
解决方案
你很接近,你可以使用函数中的参数值。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" });
推荐阅读
- c - 试图将 int* 传递给函数并在另一个 function.int* 中函数在 main 中声明
- python - Keras 神经网络。预处理
- java - 从类创建 Swagger 模型
- android - 我所有的 android 依赖项在哪里?
- mysql - 触发器不允许我更新
- ios - 索引还是标签?对于多个复选框作为 IBOutletCollection 中的按钮
- c# - C# foreach 语句不能对变量进行操作
- javascript - Javascript:创建一个动态表,第一行的列标题和第一列的行标题
- django - 如何将 datepicker 和 timepicker 添加到 Django forms.SplitDateTimeField?
- android - 调用 startActivityForResult 后检测进程死亡