npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

jsxte-wc

v1.1.5

Published

Build web components with JSXTE templates.

Readme

JSXTE-WC

Library for building web components with JSX.

  1. Basic Usage
  2. Web Component State
  3. Web Component Attributes
  4. Lifecycle
  5. Refs
  6. Other
  7. How does it work?

Installation

npm install jsxte jsxte-wc

or

yarn add jsxte jsxte-wc

Basic Usage

First set the JSX import source in the tsconfig.json:

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "jsxte"
  }
}

Note: do not enable the experimentalDecorators compiler option, JSXTE-WC leverages the ECMAScript decorators instead of the legacy TypeScript decorators.

Define a class component that extends the Element class, and include a render method.

import { Element, CustomElement } from "jsxte-wc";

@CustomElement("my-custom-element")
class MyCustomElement extends Element {
  render() {
    return (
      <div class="container">
        <span>Hello World!</span>
      </div>
    );
  }
}

Then use it:

<body>
  <my-custom-element></my-custom-element>
</body>

Web Component State

State are private properties of the component, that when changed will trigger a re-render of the component. To use it define an accessor on the component class and decorate it with the State decorator.

import { Element, CustomElement, State } from "jsxte-wc";

@CustomElement("my-custom-element")
class MyCustomElement extends Element {
  @State()
  accessor count = 0;

  handleClick = () => {
    this.count++;
  };

  render() {
    return (
      <button onclick={this.handleClick}>
        Click count: {this.count}
      </button>
    );
  }
}

Web Component Attributes

Attributes are public properties of the component, all attributes are reflected on the html declaration of the element, that when changed will trigger a re-render of the component. To use it define a property on the component class and decorate it with the Attribute decorator.

import { Element, CustomElement, Attribute } from "jsxte-wc";

@CustomElement("my-custom-element")
class MyCustomElement extends Element {
  @Attribute()
  accessor value = "";

  handleInput = (event) => {
    const { value: newValue } = event.target;

    this.value = newValue;
  };

  render() {
    return (
      <input
        type="text"
        value={this.value}
        oninput={this.handleInput}
      />
    );
  }
}

Attribute then can be specified in the html:

<body>
  <my-custom-element value="Hello World!"></my-custom-element>
</body>

Lifecycle

There are a number of lifecycle events web components built with JSXTE-WC have:

  • ElementWillUpdateEvent
  • ElementDidUpdateEvent
  • ElementDidMountEvent
  • ElementStateDidChangeEvent
  • ElementAttributeDidChangeEvent

Each of those events can be listened to by using the lifecycle property on the component class.

import {
  Element,
  CustomElement,
  ElementLifecycleEvent,
} from "jsxte-wc";

@CustomElement("my-custom-element")
class MyCustomElement extends Element {
  constructor() {
    super();

    this.lifecycle.once(ElementLifecycleEvent.DidMount, () => {
      console.log("The first render cycle has completed.");
    });
  }

  render() {
    return (
      <div class="container">
        <span>Hello World!</span>
      </div>
    );
  }
}

ElementWillUpdateEvent

This event is dispatched right before the component render method is called. This event contains no additional details.

ElementDidUpdateEvent

This event is dispatched right after the component render method is called and the results are applied to the document DOM. This event contains no additional details.

ElementDidMountEvent

This event is dispatched only once, right after the first render cycle of the component. This event contains no additional details.

ElementStateDidChangeEvent

This event is dispatcher right after a state property of the component is changed. This event contains additional details with the following signature:

const details: {
  stateName: string;
  prevValue: unknown;
  newValue: unknown;
};

ElementAttributeDidChangeEvent

This event is dispatcher right after an attribute property of the component is changed. This event contains additional details with the following signature:

const details: {
  attributeName: string;
  prevValue: unknown;
  newValue: unknown;
};

Refs

Ref object can be used to get reference to the actual DOM elements that are rendered by the component. After the component is rendered for the first time, the ref object will be updated with related element.

import {
  Element,
  CustomElement,
  ElementLifecycleEvent,
} from "jsxte-wc";

@CustomElement("my-custom-element")
class MyCustomElement extends Element {
  innerSpan = { current: null };

  constructor() {
    super();

    this.lifecycle.once(ElementLifecycleEvent.DidMount, () => {
      this.applySpanStyles();
    });
  }

  applySpanStyles() {
    if (this.innerSpan.current) {
      const elem = this.innerSpan.current;
      elem.style.color = "red";
    }
  }

  render() {
    return (
      <div class="container">
        <span ref={this.innerSpan}>Hello World!</span>
      </div>
    );
  }
}

Other

requestUpdate() function

The requestUpdate function can be used to force a re-render of the component. This is also the function that is called internally whenever a state or attribute property is changed.

How does it work?

JSXTE-WC on each render cycle produces a JSON structure of the component tree, then goes through it and compares it to the structure produced in the previous render cycle. Only the differences are used to update the DOM tree with the new attribute values and child nodes.