-1

I'm putting my hands into reason-react. In the following code :

let component = ReasonReact.statelessComponent("Component3");
let make = (~name, _children) => {
  ...component,
  render: self => <input type_="checkbox" />,
};

I don't understand what (...) means on line 3. When I delete it I get an error message :

 The record field component can't be found.

  If it's defined in another module or file, bring it into scope by:
  - Annotating it with said module name: let baby = {MyModule.age: 3}
  - Or specifying its type: let baby: MyModule.person = {age: 3}
glennsl
  • 28,186
  • 12
  • 57
  • 75
espern
  • 659
  • 6
  • 14
  • Edit : I've seen that "component" implements a "render" method by default. Does this syntax mean "take everything in the component object and add some extra features on the "render" function ? – espern Feb 13 '19 at 13:26
  • 1
    This isn't a duplicate, because it isn't ES6 or JSX but an entirely different language called Reason (which it was originally tagged correctly as). The spread syntax serves a similar purpose in Reason as in ES6 (which is where the inspiration came from) but is not entirely the same, first and foremost because it operates on strong, nominally typed records, not dynamically typed objects. – glennsl Feb 13 '19 at 14:29
  • 1
    Here's the documentation for it: https://reasonml.github.io/docs/en/record#immutable-update – glennsl Feb 13 '19 at 14:30

1 Answers1

-1

The representation is called Spread Syntax. This was introduced in ES6.

Definition and example from MDN Docs. Link at the bottom.

Spread syntax allows an iterable such as an array expression or string to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected

function sum(x, y, z) {
  return x + y + z;
}

const numbers = [1, 2, 3];

console.log(sum(...numbers));
// expected output: 6

console.log(sum.apply(null, numbers));
// expected output: 6

More details at : Spread Syntax

Karthik VU
  • 561
  • 5
  • 17