1.0.5 • Published 2 years ago

@sidww/zen v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Zen

npm version npm downloads

Dead simple state-management

  • 📦 Tiny (less than 1kb)
  • 🔩 Typesafe APIs
  • ⚡️ React and Selectors support

Install

npm i @sidww/zen

Usage

import { zen } from "@sidww/zen"

const todos = zen([{ id: 1, completed: false, title: "Idk man" }])

Reading from state

const value = todos.read()

Writing to state

todos.write([]) // Clear all todos

// Or if the next state depends on previous one

todos.write((prev) => [
  ...prev,
  { id: 123, title: "Last one", completed: true },
])

// U can also directly use the .read() method instead

Subscribing to changes

todos.subscribe((state) => {
  console.log("CHANGE: ", state)
})

Usage with React

import { useZen } from "@sidww/zen/react"

const todos = useZen(todosZen);

Selector support

import { useZen } from "@sidww/zen/react"

const firstTodo = useZen(todosZen, (s) => s[0]);

Type docs: https://paka.dev/npm/@sidww/zen

License

MIT © sidwebworks

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago