Skip to content

Instantly share code, notes, and snippets.

@iamandrewluca
Created January 27, 2020 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamandrewluca/35d7e1fa10c379d1c3e306413742d29a to your computer and use it in GitHub Desktop.
Save iamandrewluca/35d7e1fa10c379d1c3e306413742d29a to your computer and use it in GitHub Desktop.
import React from "react";
import ReactDOM from "react-dom";
function App() {
return (
<div>
<hr />
{joinJSX(
[
<span key={3}>1</span>,
<span key={1}>2</span>,
<span key={2}>3</span>
],
<hr />
)}
<hr />
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
function joinJSX(components, separator) {
const joined = [];
for (
let i = 0, l = components.length, c = components[i];
i < l;
++i, c = components[i]
) {
if (joined.length !== 0) {
joined.push({ ...separator, key: separator.type + i }, c);
} else {
joined.push(c);
}
}
return joined;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment