--- title: Quick Start id: quick-start --- The basic Lit app example to get started with TanStack `lit-store`. You can use `TanStackStoreSelector` in two ways: - Trigger rerenders when a selected slice changes - Access the selected value directly through `.value` ```ts import { LitElement, html } from 'lit' import { customElement, property } from 'lit/decorators.js' import { TanStackStoreSelector, createStore } from '@tanstack/lit-store' // You can instantiate a Store outside of Lit components too! export const store = createStore({ dogs: 0, cats: 0, }) type Animal = 'dogs' | 'cats' const updateState = (animal: Animal) => { store.setState((state) => ({ ...state, [animal]: state[animal] + 1, })) } @customElement('animal-display') export class AnimalDisplay extends LitElement { @property({ type: String }) animal: Animal = 'dogs' // Subscribes only to `state[animal]` counter = new TanStackStoreSelector( this, () => store, (state) => state[this.animal], ) render() { return html`

Using selector.value: ${this.counter.value}

Reading directly from store.state: ${store.state[this.animal]}

` } } @customElement('animal-increment') export class AnimalIncrement extends LitElement { @property({ type: String }) animal: Animal = 'dogs' render() { return html` ` } } @customElement('tanstack-store-demo') export class TanStackStoreDemo extends LitElement { render() { return html`

How many of your friends like cats or dogs?

Press one of the buttons to increment how many of your friends like cats or dogs.

` } } ``` `selector.value` returns the latest selected value and only updates when that specific selection changes. Reading from `store.state` accesses the full store state directly. The component still rerenders because the selector subscription is active, but the rendered value itself comes from the store. Then mount the root element in your HTML: ```html ```