Search code examples
reactjsreact-functional-component

Is there a way to get arguments after distructuring?


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?


Solution

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