alexmingoia / purescript-pux

Build type-safe web apps with PureScript.
https://www.purescript-pux.org
Other
566 stars 76 forks source link

Invoke React.createElement correctly when passing it children #51

Closed wereHamster closed 8 years ago

wereHamster commented 8 years ago

The prototype of React.createElements is:

ReactElement createElement(
  string/ReactClass type,
  [object props],
  [children ...]
)

The children array is not passed in the third argument, but instead passed as varargs.

The syntax of calling functions with varargs is easier in ES2015 with the spread operator: React.createElement(comp, props, ...children). In ES5, we have to use .apply.

This avoids the React warning about missing keys. This warning is only generated if one of the children is an array (technically allowed, but each item therein must have a key prop).

In short, this generates a warning:

React.createElement(comp, props, [someChild, anotherChild])

while this does not:

React.createElement(comp, props, someChild, anotherChild)
wereHamster commented 7 years ago

@alexmingoia I noticed just now but you removed the changes on line 50/51. Was that intentional?

This is the merge commit: https://github.com/alexmingoia/purescript-pux/commit/cc7acbd3b51340fcb609c55b05a69c6d8b1cfc83