question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for components that return arrays

See original GitHub issue

We 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:closed
  • Created 6 years ago
  • Comments:26 (22 by maintainers)

github_iconTop GitHub Comments

3reactions
zacenocommented, Sep 13, 2017

@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”)

3reactions
leeoniyacommented, Sep 13, 2017

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found