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

@nexus-state/svelte

v0.1.7

Published

> Svelte integration for Nexus State — fine-grained reactivity with Svelte stores > > [![npm version](https://img.shields.io/npm/v/@nexus-state/svelte)](https://www.npmjs.com/package/@nexus-state/svelte) > [![Coverage for svelte package](https://coveralls

Readme

@nexus-state/svelte

Svelte integration for Nexus State — fine-grained reactivity with Svelte stores

npm version Coverage for svelte package npm downloads License

DocumentationRepository


🚀 Quick Start (60 seconds)

<script lang="ts">
  import { atom, createStore } from '@nexus-state/core';
  import { useAtom } from '@nexus-state/svelte';

  // Create atom and store
  const countAtom = atom(0, 'count');
  const store = createStore();

  // useAtom returns a Readable store (use $ prefix)
  const count = useAtom(countAtom, store);

  function increment() {
    store.set(countAtom, $count + 1);
  }
</script>

<div>
  <p>Count: {$count}</p>
  <button on:click={increment}>+</button>
</div>

Minimum required: Svelte 3.0.0


🎯 Why Nexus State for Svelte?

Comparison with Alternatives

| Feature | Nexus State | Svelte Store | Zustand | |---------|-------------|--------------|---------| | Fine-grained updates | ✅ Per-atom | ⚠️ Manual | ❌ | | Computed atoms | ✅ Built-in | ⚠️ Derived | ❌ | | Multi-framework | ✅ React/Vue/Svelte | ❌ Svelte-only | ✅ | | DevTools | ✅ Redux DevTools | ❌ | ⚠️ Custom | | Bundle size | 1.2KB | 0.5KB | 1KB |

✅ Choose Nexus State if you need:

  • Fine-grained reactivity (per-atom updates)
  • Computed atoms with automatic recalculation
  • Multi-framework state sharing
  • Isolated stores (SSR, testing)

❌ Use alternatives if:

  • Simple local state → Svelte writable() (built-in)
  • Svelte-only project → Svelte stores (native integration)
  • Simple global state → Zustand (lighter)

📖 Store Integration

useAtom(atom, store?)

Returns a Svelte Readable store. Use $ prefix to subscribe.

<script lang="ts">
  import { useAtom } from '@nexus-state/svelte';

  const count = useAtom(countAtom, store);
  // count is Readable<number>, use $count in template
</script>

<div>Count: {$count}</div>

useAtomValue(atom, store?)

Read-only access. Returns Readable.

<script lang="ts">
  import { useAtomValue } from '@nexus-state/svelte';

  const count = useAtomValue(countAtom, store);
</script>

<div>Count: {$count}</div>

useSetAtom(atom, store?)

Returns setter function.

<script lang="ts">
  import { useSetAtom } from '@nexus-state/svelte';

  const setCount = useSetAtom(countAtom, store);

  function increment() {
    setCount(c => c + 1);
  }
</script>

<button on:click={increment}>+</button>

Computed Atoms

<script lang="ts">
  import { atom } from '@nexus-state/core';
  import { useAtomValue } from '@nexus-state/svelte';

  const countAtom = atom(0);
  const doubleAtom = atom((get) => get(countAtom) * 2);

  const count = useAtomValue(countAtom, store);
  const double = useAtomValue(doubleAtom, store);
</script>

<p>{$count} × 2 = {$double}</p>

Multiple Stores

<script lang="ts">
  import { atom, createStore } from '@nexus-state/core';
  import { useAtom } from '@nexus-state/svelte';

  const store1 = createStore();
  const store2 = createStore();

  const value1 = useAtom(atom1, store1);
  const value2 = useAtom(atom2, store2);
</script>

<div>
  <p>Store 1: {$value1}</p>
  <p>Store 2: {$value2}</p>
</div>

SSR with Isolated Stores

<script lang="ts">
  import { atom, createStore } from '@nexus-state/core';
  import { useAtom } from '@nexus-state/svelte';

  export let initialState;

  // Create isolated store per request
  const store = createStore();
  if (initialState) {
    store.setState(initialState);
  }

  const user = useAtom(userAtom, store);
</script>

<div>{$user?.name}</div>

🔌 Integration with Ecosystem

Data Fetching (@nexus-state/query)

<script lang="ts">
  import { useQuery } from '@nexus-state/query/svelte';
  import { useAtomValue } from '@nexus-state/svelte';

  const userId = useAtomValue(userIdAtom, store);

  const { data: user, isLoading } = useQuery({
    queryKey: ['user', userId],
    queryFn: fetchUser,
  });
</script>

{#if $isLoading}
  <div>Loading...</div>
{:else}
  <div>{$user.name}</div>
{/if}

📖 Full docs: npm


Persistence (@nexus-state/persist)

<script lang="ts">
  import { persistAtom } from '@nexus-state/persist';
  import { useAtomValue } from '@nexus-state/svelte';

  // Persist atom to localStorage
  const settingsAtom = persistAtom(
    { theme: 'light' },
    'settings',
    { storage: 'localStorage' }
  );

  const settings = useAtomValue(settingsAtom, store);
</script>

<div>Theme: {$settings.theme}</div>

📖 Full docs: npm


📚 API Reference

| Function | Signature | Description | |----------|-----------|-------------| | useAtom | useAtom(atom, store?) | Read + write (returns Readable) | | useAtomValue | useAtomValue(atom, store?) | Read only (returns Readable) | | useSetAtom | useSetAtom(atom, store?) | Write only (returns function) |


🔧 Troubleshooting

1. Store not updating in template

Cause: Not using $ prefix to subscribe.

Solution:

<script>
  const count = useAtom(countAtom, store);
</script>

<!-- ❌ Won't update -->
<div>{count}</div>

<!-- ✅ Will update -->
<div>{$count}</div>

2. "Cannot read properties of undefined" error

Cause: Store not provided.

Solution:

<script>
  // Provide store explicitly
  const count = useAtom(countAtom, store);
</script>

3. Memory leak in SSR

Cause: Store not cleaned up between requests.

Solution: Create new store per request.

<script>
  // ✅ Correct - new store per component instance
  const store = createStore();
  
  // ❌ Wrong - shared store
  // const store = createStore(); // at module level
</script>

📦 Related Packages

| Package | Description | npm | |---------|-------------|-----| | @nexus-state/core | Core concepts (atoms, stores) | Install | | @nexus-state/react | React integration | Install | | @nexus-state/vue | Vue integration | Install | | @nexus-state/query | Data fetching | Install | | @nexus-state/async | Simple async state | Install | | @nexus-state/persist | LocalStorage persistence | Install |


🔗 See Also

Full ecosystem: Nexus State Packages


📄 License

MIT