Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lit-element

Package Overview
Dependencies
Maintainers
11
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lit-element

A simple base class for creating fast, lightweight web components

  • 2.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2M
increased by3.19%
Maintainers
11
Weekly downloads
 
Created

What is lit-element?

The lit-element package is a simple base class for creating fast, lightweight web components with the Lit library. It provides a declarative template system that ties your markup to your component's properties and state, along with reactive updates and a component lifecycle.

What are lit-element's main functionalities?

Declarative Templates

LitElement uses `html` tagged template literals to define templates that are bound to the component's properties. When properties change, the template is efficiently re-rendered.

import { LitElement, html } from 'lit-element';

class MyElement extends LitElement {
  static get properties() {
    return {
      message: { type: String }
    };
  }

  constructor() {
    super();
    this.message = 'Hello, World!';
  }

  render() {
    return html`<p>${this.message}</p>`;
  }
}
customElements.define('my-element', MyElement);

Reactive Properties

Properties can be made reactive using the `@property` decorator. When a reactive property changes, LitElement automatically updates the component's template.

import { LitElement, html, property } from 'lit-element';

class MyElement extends LitElement {
  @property({ type: String }) greeting = 'Hello';

  render() {
    return html`<h1>${this.greeting}, World!</h1>`;
  }
}
customElements.define('my-element', MyElement);

Lifecycle Methods

LitElement provides lifecycle methods such as `firstUpdated`, `updated`, and `disconnectedCallback` for managing the component's lifecycle events.

import { LitElement } from 'lit-element';

class MyElement extends LitElement {
  firstUpdated(changedProperties) {
    console.log('Component first updated!');
  }

  updated(changedProperties) {
    console.log('Component updated with changed properties:', changedProperties);
  }

  disconnectedCallback() {
    console.log('Component removed from the DOM!');
  }
}
customElements.define('my-element', MyElement);

Other packages similar to lit-element

FAQs

Package last updated on 19 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc