Skip to content

dene-/sveltinia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sveltinia

Sveltinia

Sveltinia stores for Svelte and SvelteKit.
Typed stores, persistence, plugins, action hooks, mutation subscriptions, request-safe SSR.

npm package managers Svelte 5 TypeScript docs docs build

Sveltinia is a Svelte 5 state management library inspired by Pinia. It provides typed stores for Svelte and SvelteKit, persisted Svelte stores, action hooks, mutation subscriptions, plugins, and request-safe SvelteKit SSR state management.

Use it when you want a Pinia alternative for Svelte, familiar SvelteKit Pinia-style ergonomics, or a small store API without a framework-sized abstraction.

Install

Install it with whichever package manager your project already uses:

npm install sveltinia
# or: yarn add sveltinia
# or: pnpm add sveltinia
# or: bun add sveltinia

Quick start

import { createSveltinia, defineStore } from 'sveltinia'

export const sveltinia = createSveltinia({ debug: import.meta.env.DEV })

export const useCounter = defineStore('counter', {
  state: () => ({ count: 0 }),
  getters: { double: (state) => state.count * 2 },
  actions: { increment() { this.count++ } },
  persist: true
})

Install first-party plugins once per root:

import { createDebugPlugin, createPersistedState } from 'sveltinia'

sveltinia.use(createDebugPlugin()).use(createPersistedState())

Use the store in application code:

const counter = useCounter(sveltinia)
counter.increment()
console.log(counter.double)

In a Svelte component, adapt it to a Svelte readable store:

<script lang="ts">
  import { useStore } from 'sveltinia/svelte'
  import { fromStore } from 'svelte/store'
  import { useCounter } from '$lib/stores/counter'

  const counter = fromStore(useStore(useCounter()))
</script>

<button onclick={() => counter.current.increment()}>{counter.current.count}</button>

Docs

Release

yarn publish:dry
yarn publish:npm

Update packages/sveltinia/package.json before publishing. Published npm versions are immutable.

Contributor

Built and maintained by dene-.

About

Sveltinia is a Svelte 5 state management library inspired by Pinia. It provides typed stores for Svelte and SvelteKit, persisted Svelte stores, action hooks, mutation subscriptions, plugins, and request-safe SvelteKit SSR state management.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors