Support for components that return arrays
See original GitHub issueWe often have use cases where our components need to return arrays, e.g.
var SomePageComponent = function (props) {
props = props || {};
return [<Header />,
<SideNav />,
<div class="panel panel--main">...</div>
];
};
However, it isn’t easy for us to really do so in HyperApp. I’ve written a polyfill for exactly that (using jQuery, along with other polyfill code for backward compatibility):
function patch(parent, element, oldNode, node, isSVG, nextSibling) {
if ($.isArray(node)) {
return $.map(node, function (t, i) {
return patch(parent, element, i === node.length - 1 ? oldNode : null, t, isSVG, nextSibling);
});
}
if ($.isArray(element)) {
var remaining = element.slice(1);
element = element[0];
$(remaining).remove();
}
// original code ...
}
I do not quite know whether there would still be issues with components returning arrays.
Will HyperApp officially support that?
Issue Analytics
- State:
- Created 6 years ago
- Comments:26 (22 by maintainers)
Top Results From Across the Web
How can I return a array with React Components?
The ReturnPokemon component receives two arrays and sends back the array accordingly with the props it's receiving. Now the Landing component ...
Read more >Understanding How To Render Arrays in React | DigitalOcean
This article will teach you how to render an array in React and the best practices to use when rendering different elements within...
Read more >Lists and Keys - React
In React, transforming arrays into lists of elements is nearly identical. Rendering Multiple Components. You can build collections of elements and include them ......
Read more >[@types/react] React Component does not allow returning an ...
If you know how to fix the issue, make a pull request instead. I tried using the @types/react (version 16.9.19) package and had...
Read more >Manipulating Arrays and Objects in State with React | Pluralsight
In React, every component can handle its own state. This guide covers how to manipulate state with objects and arrays.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@infinnie Ok yeah I see … that could probably work. It would get weird with keys though, but that may not be problem if the use cases don’t overlap.
I’d suggest making a PR, but I also understand you want to get a feel for how it would be received before putting in the work.
(If/when you do make a PR: don’t use jQuery or polyfills – one of Hyperapp’s key benefits is “no dependencies”)
in my experience, robust, optimal and fast dom reconciliation of fragments is non-trivial. i’d be interested to see what you guys come up with and how much code it adds.
https://github.com/developit/preact/pull/703#issuecomment-322791946