Skip to content

Fragment (empty) tag support #137

Description

@thescientist13

Summary

One rule with JSX is that there can only be one top level node in the render tree.

export default class Header extends HTMLElement {

  connectedCallback() {
    this.render();
  }

  render() {
    return (
      <header>
        <nav>...</nav>
      </header>
      <h1>Welcome to my website!</h1>
    );
  }
}

customElements.define('app-header', Header);

Screenshot 2024-01-06 at 12 57 48 PM

Details

The "fragment" wrapping tag convention can effectively act as a pass through tag that wont be part of the rendered output, but helps from a quality of life perspective when authoring JSX

export default class Header extends HTMLElement {

  connectedCallback() {
    this.render();
  }

  render() {
    return (
      <>
        <header>
          <nav>...</nav>
        </header>
        <h1>Welcome to my website!</h1>
      </>
    );
  }
}

customElements.define('app-header', Header);

Activity

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

    JSXfeatureNew feature or request

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions