Skip to content

Document fragment as multiple elements #15

Closed

Description

@dy

There was a discussion in JSX spec to enable fragments as first class citizen via just multiple elements, which is really natural syntax for fragments, react/jsx#58.
For me that would be a killing feature for htm.

return html`
            <${Header} name="ToDo's (${page})" />
            <ul>
              ${todos.map(todo => html`
                <li>${todo}</li>
              `)}
            </ul>
            <button onClick=${this.addTodo.bind(this)}>Add Todo</button>
            <${Footer}>footer content here<//>
        `;

Any thoughts on enabling that?

Activity

  1. changed the title [-]Document fragment directly[/-] [+]Document fragment as multiple elements[/+] on Nov 21, 2018
  2. developit commented on Nov 21, 2018

    @developit
    Owner

    Definitely want to get that supported! I haven't tested since Fragments aren't yet available in Preact, but it'd be nice to support the syntax so that React users can use it.

    Currently you'd have to do this:

            return html`
              <${Fragment}>
                <${Header} name="ToDo's (${page})" />
                <ul>
                  ${todos.map(todo => html`
                    <li>${todo}</li>
                  `)}
                </ul>
                <button onClick=${this.addTodo.bind(this)}>Add Todo</button>
                <${Footer}>footer content here<//>
              <//>
            `;
  3. added
    enhancement
    on Nov 21, 2018
  4. manucorporat commented on Nov 25, 2018

    @manucorporat
  5. added
    has fix
    on Dec 29, 2018
  6. jviide commented on Jul 8, 2019

    @jviide
    Collaborator

    Support for this was added in v2.1.0 🙌And it works great with Preact X (current preact@next, see this CodeSandbox example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhas fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions