Skip to content

sagiereder/zustand-boilerplate

Repository files navigation

zustand-boilerplate

npm version npm downloads

Features:

  • Quickly generate basic state actions for your zustand store

Example

you'll need to install zustand & reflect-metadata for zustand-boilerplate to work

import { create } from "zustand"
import * as Z from "zustand-boilerplate"

interface Bear {
  name: string
}

class BearStore {
  @Z.Boolean()
  isDangerous = false

  @Z.Number()
  count = 0

  @Z.Array()
  bears: Bear[] = []

  //
  // Notice you have to set a default value and apply the decorator
  // to properties for generated actions to work
  //
  @Z.Any()
  mainBear: Bear | undefined = undefined

  @Z.String()
  userName: string | undefined = undefined
}

const bearStoreWithActions = Z.generateStoreWithActions(BearStore)

export const store = create(bearStoreWithActions)

Install

npm i zustand-boilerplate

License

MIT ©

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published