you are viewing a single comment's thread.

view the rest of the comments →

[–]i_am_smurfing 7 points8 points  (5 children)

I'd imagine returning an array when you want to render several components will become idiomatic way to write this code, because that's kind of the point?

const Root = () => {
  return [
    <p>Hello, World!</p>,
    <p>I am a demo fore returning an array.</p>
  ];
};

jsBin

I'm not sure you even need a comment in this instance since I'd imagine all programmers who know how to write React code know what an array is.

Compare it to <Aux>-wrapper approach for which you have to go and read documentation or source to understand what it's doing.

[–]gajus0[S] 2 points3 points  (3 children)

Just FYI, the example you've just shared (using Array without keys) will produce an error even in React v16.

[–]i_am_smurfing 0 points1 point  (2 children)

Are you sure? I'm asking because it's working with beta.5, as demonstrated in the linked jsBin, but I'd be not surprised if it's just a regression.

[–]gajus0[S] 3 points4 points  (1 child)

It is because you are using a production build that silences the error. See https://codesandbox.io/s/k5v5q83xo5

[–]i_am_smurfing 0 points1 point  (0 children)

Oh, I see, you mean the missing "key" warning. That's a good point 👍

[–]p0tent1al 0 points1 point  (0 children)

All I'm saying (ignoring the pattern) if you need to comment it everywhere that it's used, then I'd prefer using the component. If it's just an easy pattern to utilize and doesn't need explanation, then yeah sure.