Skip to content
On this page

Stores

Overview

Spire doesn't have its own Store system, instead it relies on Pinia Stores.

Syncing to LocalStorage

WARNING

This helper is not yet available in this form.

If you need to sync your Store to local or session storage, you can use Spire's syncStoreLocal() helper.

This is an example of a sync of a store to localStorage that will replace all string dates to dayjs objects on restoring:

ts
import { syncStoreLocal } from "@/toolkit"

syncStoreLocal(useCustomerStore(), (data, store) => {
    replaceDateRecursive(data)

    store.$state = data
})

If you need to sync to sessionStorage instead you can use syncStoreSession().

Default App Store

Spire provides an AppStore by default to take care of its own state, like what Layout and Language are currently active.

You can extend this Store with your own data as needed by passing your options into the CustomAppStore type in stores/app.store.ts:

ts
type CustomAppStore = AppStore<{
    // myKey: boolean
}>

WARNING

Make sure you also set the default state of your added keys, otherwise pinia will not be able to track them!