@evolify/tiny
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

tiny

Tiny utils for web develop

install

pnpm add @evolify/tiny

tiny-store

tiny store for React

usage

  • create store
// store.js
import Store from "@evolify/tiny/store"

const initialState = {
  tasks: [],
  counter: 0
}

export const store = new Store(initialState)

export function addTask(title){
  store.update({
    tasks: store.state.tasks.concat({
      title,
      updateTime: Date.now()
    })
  })
}

export function increase(){
  store.update(state => ({
    counter: state.counter + 1
  }))
}

export { store, addTask, increase }
  • use store
// App.jsx
import { store, increase } from "./store.js"

export function App(){
  // Get whole state and destruct
  const { counter } = store.use()
  // or get needed state
  const tasks = store.use(state => state.tasks)

  return (
    <div className="page">
      <button onClick={increase}>{counter}</button>
    </div>
  )
}

Readme

Keywords

Package Sidebar

Install

npm i @evolify/tiny

Weekly Downloads

5

Version

0.2.1

License

MIT

Unpacked Size

9.74 kB

Total Files

11

Last publish

Collaborators

  • evolify