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

@penio/lit-rtk-query

v0.2.0

Published

Lit reactive controllers and hooks for RTK Query and Redux state integration

Readme

lit-rtk-query

Lit reactive controllers and hooks that integrate RTK Query and Redux state into Lit web components.

  • Zero boilerplate — drop a controller or generated hook into your element and the query lifecycle (loading, caching, re-fetching, cleanup) is handled automatically.
  • Precise re-renders — updates are gated on reference equality so unrelated Redux dispatches never trigger spurious renders.
  • Dual-Input Parameter Tracking — derive query arguments seamlessly from both global Redux state and local Lit component properties simultaneously.
  • Full TypeScript inference — UI state is accurately narrowed to your endpoint's exact shapes without intrusive inline type assertions.

Installation

npm install lit-rtk-query

Peer dependencies (install alongside if not already present):

npm install lit @reduxjs/toolkit

Usage

RTKQueryController — class-based

The controller orchestrates cache subscriptions and binds updates directly to the component. State properties are exposed under the .state object.

import { LitElement, html } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { RTKQueryController } from 'lit-rtk-query';
import { store } from './store.js';
import { api } from './api.js';

@customElement('product-list')
class ProductList extends LitElement {
  @state() private _page = 1;

  products = new RTKQueryController(
    this,
    () => store,
    api.endpoints.getProducts,
    { 
      // Receives both global Redux state AND the Lit host element instance
      argSelector: (state, host) => ({ 
        storeId: state.auth.user?.merchant ?? 'DEFAULT',
        page: host._page 
      }) 
    },
  );

  render() {
    const { data = [], isLoading, error } = this.products.state ?? {};
    if (isLoading) return html`<p>Loading…</p>`;
    if (error)     return html`<p>Error</p>`;
    return html`<ul>${data.map(p => html`<li>${p.name}</li>`)}</ul>`;
  }
}

createLitHooks — generate hooks from an entire RTK Query API

Generate specialized, type-safe functional hooks for your components. To avoid initialization race conditions with this in TypeScript class fields, initialize query hooks cleanly inside your component constructor.

import { LitElement, html } from 'lit';
import { state } from 'lit/decorators.js';
import { createLitHooks, type UseQueryResult } from 'lit-rtk-query';
import { api } from './api.js';

// Generates useGetProducts, useCreateProduct, etc. from api.endpoints
const { useGetProducts, useCreateProduct } = createLitHooks(api);

class ProductList extends LitElement {
  @state() private _page = 1;

  // Declare properties at the class level
  products: UseQueryResult<any>;
  create: any;

  constructor() {
    super();

    // Initialize hooks safely in the constructor where 'this' context is fully baked
    this.products = useGetProducts(this, (state, host) => ({
      storeId: state.auth.user?.merchant ?? 'DEFAULT',
      page: host._page,
    }));

    this.create = useCreateProduct(this);
  }

  render() {
    const { data = [], isLoading } = this.products.state ?? {};

    return html`
      <button @click=${() => this.create.trigger({ name: 'Widget' })}>
        Add Widget
      </button>
      ${isLoading ? html`<p>Loading...</p>` : ''}
      <ul>${data.map(p => html`<li>${p.name}</li>`)}</ul>
    `;
  }
}

SelectorController — generic Redux selector

Subscribes to any slice of Redux state without coupling to RTK Query:

import { SelectorController } from 'lit-rtk-query';
import { store } from './store.js';

class CartBadge extends LitElement {
  count = new SelectorController(
    this,
    () => store,
    (state: AppState) => state.cart.itemCount,
  );

  render() {
    return html`<span>${this.count.value}</span>`;
  }
}

Pass a custom equality function as the fourth argument to avoid re-renders when an object reference changes but the values remain identical:

import { shallowEqual } from '@reduxjs/toolkit';

summary = new SelectorController(this, () => store, selectSummary, shallowEqual);

API Reference

RTKQueryController<TArg, TData, THost>

| Member | Type | Description | | :--- | :--- | :--- | | state | QueryState<TData> \| undefined | Combined UI lifecycle states (data, isLoading, isFetching, error, etc.) | | refetch() | void | Forces the query to update, bypassing the Redux cache | | hostConnected() | void | Automatically handles Redux store subscription mapping on element mount | | hostDisconnected() | void | Unsubscribes and frees up memory automatically on unmount |

SelectorController<TState, TSelected, THost>

| Member | Type | Description | | :--- | :--- | :--- | | value | TSelected \| undefined | Current selected value; undefined until connected |

RTKQueryOptions<THost, TArg>

| Option | Type | Default | Description | | :--- | :--- | :--- | :--- | | argSelector | (state: any, host: THost) => TArg | () => undefined | Evaluates parameters dynamically from both Redux and local Lit properties | | lazy | boolean | false | Skips the automatic evaluation/fetching sequence on connect |

License

MIT