--- 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]}
Press one of the buttons to increment how many of your friends like cats or dogs.