1

I see something like then following.

render() {
  <Foo {...this.props} />
}

I know what it does but can someone confirm that this is actually not the spread syntax used in ES2015 (or indeed the proposed object spread syntax) and that it is instead a JSX-specific syntax that looks like the ES spread syntax?

Here the curly braces are JSX delimiters for a JavaScript expression and ...this.props is not a valid standalone expression in normal JavaScript.

Ben Aston
  • 53,718
  • 65
  • 205
  • 331
  • JSX itself is not a valid standalone expression.So I guess yes, its a JSX specific syntax – Rajesh Aug 17 '17 at 13:27
  • 1
    It's not ES spread, it's JSX spread. All of your JSX is getting transpiled to JS/ES. – ivarni Aug 17 '17 at 13:27
  • This might help: https://stackoverflow.com/questions/32363911/trouble-understanding-jsx-spread-operator – Rajesh Aug 17 '17 at 13:28
  • 1
    I was confused when I saw that `` was not valid, while `` was working on the other hand. I became suspicious about it not actually being an _"object literal spread"_ operator, but rather a _"function argument spread"_ operator, which turned out to be the case when I checked the transpiled code, which explains the difference. (Meaning, it's actually used like `f(...rest)` instead of `{...rest}`.) I think that this is not emphasized enough in the answers linked as reason for the close vote... – Isti115 Oct 21 '22 at 13:26

0 Answers0