# Framework adapters

[One state for several frameworks →](/for/multi-framework/)

### React

`useStore($cart)`

[@nanostores/react ↗](https://github.com/nanostores/react#readme)official

### Preact

`useStore($cart)`

[@nanostores/preact ↗](https://github.com/nanostores/preact#readme)official

### Vue

`useStore($cart)`

[@nanostores/vue ↗](https://github.com/nanostores/vue#readme)official

### Svelte

`$cart — Svelte’s store contract`

[built in ↗](https://github.com/nanostores/nanostores#svelte)no adapterRunes: [@nanostores/svelte-runes ↗](https://github.com/nanostores/svelte-runes#readme) official

### Solid

`useStore($cart)`

[@nanostores/solid ↗](https://github.com/nanostores/solid#readme)official

### Lit

`new StoreController(this, $cart)`

[@nanostores/lit ↗](https://github.com/nanostores/lit#readme)official

### Angular

`nanostores.useStore($cart)`

[@nanostores/angular ↗](https://github.com/nanostores/angular#readme)official

### Alpine.js

`x-nano:cart="$cart"`

[@nanostores/alpine ↗](https://github.com/nanostores/alpine#readme)official

### Vanilla JS · Web Components

`$cart.subscribe(render)`

[built in ↗](https://github.com/nanostores/nanostores#vanilla-js)no adapterComponents: [nanotags ↗](https://psd-coder.github.io/nanotags) community

## Store utilities

Persistence, data fetching, routing, translations, media queries, and nested state.

### Persistence

Swap atom for persistentJSON. The value is saved to localStorage, and other open tabs get every change.

[@nanostores/persistent →](/docs/ecosystem/persistent/)official

stores/cart.ts

```
export const $cart = persistentJSON<Product[]>('cart', [])
```

On the server there is no localStorage: the store starts from its initial value.

[Used in: Mostly HTML, a few parts share state →](/for/static-page/)

### Data fetching

A fetcher store loads on the first subscriber, caches by key and shares the result. Every widget just reads $products.

[@nanostores/query →](/docs/ecosystem/query/)official

stores/products.ts

```
export const [createFetcherStore] = nanoquery({
  fetcher: (...keys) => fetch(keys.join('')).then((r) => r.json()),
})

export const $products = createFetcherStore<Product[]>(['/api/products'])
```

Already on TanStack Query? Keep it for server data and use stores for client state.

### Routing

The router is a store of the current page. Read the query string as one more computed store.

[@nanostores/router →](/docs/ecosystem/router/)officialOnly the query string: [@vp-tw/nanostores-qs ↗](https://github.com/VdustR/nanostores-qs#readme) community

stores/router.ts

```
export const $router = createRouter({
  catalog: '/catalog',
  product: '/products/:id',
})

// /catalog?color=red → { color: 'red' }
export const $filters = computed($router, (page) => page?.search ?? {})
```

### Translations

Components declare their strings in the base language. Translations for the current locale load on demand.

[@nanostores/i18n →](/docs/ecosystem/i18n/)official

stores/i18n.ts

```
export const $locale = localeFrom(browser({ available: ['en', 'de'] }))

export const i18n = createI18n($locale, {
  get: (code) => fetch(`/i18n/${code}.json`).then((r) => r.json()),
})

export const $cartMessages = i18n('cart', {
  title: 'Your cart',
})
```

### Media queries

No plugin needed. onMount starts listening when the first component subscribes and stops after the last one leaves.

[onMount →](/docs/api/#onmount)coreReady-made store: [@nanostores/media-query ↗](https://github.com/nanostores/media-query#readme) official

stores/layout.ts

```
export const $isMobile = atom(false)

onMount($isMobile, () => {
  const query = matchMedia('(max-width: 767px)')
  const update = () => $isMobile.set(query.matches)
  update()
  query.addEventListener('change', update)
  return () => query.removeEventListener('change', update)
})
```

### Nested state

Update a field by its path instead of copying the whole object by hand.

[@nanostores/deepmap ↗](https://github.com/nanostores/deepmap#readme)official

stores/checkout.ts

```
export const $checkout = deepMap({
  name: '',
  address: { city: '', zip: '' },
})

export function setCity(city: string) {
  $checkout.setKey('address.city', city)
}
```

Flat object? map in the core has setKey too.

More packages

### Need computed values from async sources?

[@nanostores/async ↗](https://github.com/nanostores/async#readme)official

### Need a SQLite SELECT as a reactive store?

[@nanostores/sql ↗](https://github.com/nanostores/sql#readme)official

### Need Google Tag Manager dataLayer pushes as a store?

[@vp-tw/nanostores-data-layer ↗](https://github.com/vp-tw/nanostores-data-layer#readme)community

### Need headless form state?

[@alexcarpenter/form ↗](https://github.com/alexcarpenter/form#readme)community

### Need Immer-style immutable updates?

[@illuxiza/nanostores-immer ↗](https://github.com/illuxiza/nanostores-immer#readme)community

### Need WebSocket sync with CRDT conflict resolution?

[@logux/client ↗](https://github.com/logux/client#readme)community

### Need a state machine?

[@alexcarpenter/machine ↗](https://github.com/alexcarpenter/machine#readme)community

### Need sessionStorage, memory or custom storage adapters?

[@vp-tw/nanostores-storage ↗](https://github.com/vp-tw/nanostores-storage#readme)community

[Missing a package? Tell us →](https://github.com/nanostores/nanostores/discussions)

## Devtools

Your stores in the Redux DevTools panel, named for you. Or a plain console log when that is enough.

### Which line wrote this value?

Every store appears in the Redux DevTools panel, named after the variable you wrote. Each change gets its own timeline row with a diff and a stack trace to the line that wrote it.

[nanostores-devtools →](/docs/ecosystem/devtools/)community

* No setup per store
* Dev builds only — production gets empty functions
* Vite, webpack, Rspack · trackStores() elsewhere

vite.config.ts

```
export default defineConfig({
  plugins: [nanostoresDevtools()],
})
```

main.ts

```
connectDevtools({ name: 'my-shop' })
```

### Print every change to the console

No browser extension: store changes and lifecycle events appear in the console under the names you pass.

[@nanostores/logger ↗](https://github.com/nanostores/logger#readme)official

dev.ts

```
logger({ Cart: $cart })
```

### Already working in Vue Devtools?

The Vue integration adds your stores to the Vue Devtools panel.

[@nanostores/vue ↗](https://github.com/nanostores/vue#devtools)official

nanostores-devtools only reads state, so there is no time travel. **Built your workflow around it? Redux Toolkit is the stronger fit.**

[**Getting started →**&#x59;our first store and component in a few minutes.](/docs/getting-started/)[**Find your situation →**&#x49;slands, Context, live data, several frameworks.](/)
