ProjectEvergreen / wcc

Experimental native Web Components compiler.
https://merry-caramel-524e61.netlify.app
90 stars 7 forks source link

Fragment (empty) tag support #137

Open thescientist13 opened 10 months ago

thescientist13 commented 10 months ago

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);