Is there a way to get arguments after distructuring?

Viewed 27

I was trying to get list of arguments from inside of the functional component in React.

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

so is there a was to get all arguments after I distructured them?

2 Answers

You are close, you can use the arguments value from the function. arguments is an array-like object and since the function consumes only a single argument you access the zeroth element.

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" });

How about moving the destructuring to the second line:

export function SomeFunction (props) {
  const { first, second, third } = props;
  //...
}

If ever you need to reference the entire props object, you can do so via props.

Related