0

I understand ES6 destructure and spread operators, but I am confused by their usage together. Can someone break this down into a way a layman can understand?

const index = ({title, description, ...props}) => {
  return (
    <div>
      
    </div>
  )
}

How does this work?

3
  • 1
    That's not spread, it's rest syntax - part of the destructuring syntax. It collects "everything else" into props - in this case, anything that is not title or description Commented Oct 22, 2020 at 13:26
  • 3
    See rest in object destructuring on MDN Commented Oct 22, 2020 at 13:27
  • From the MDN link above: let {a, b, ...rest} = {a: 10, b: 20, c: 30, d: 40}; //rest = { c: 30, d: 40 } Commented Oct 22, 2020 at 20:54

1 Answer 1

1

Something like this. Where everythingElseExceptTitleAndDescription creates a new object with all enumerable own properties of the argument except title and description

const index = (arg) => {
  let title = arg.title;
  let description = arg.description;
  let props = everythingElseExceptTitleAndDescription(arg);
  return (
    <div>
      
    </div>
  )
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.