0.1.1 • Published 2 years ago
vanilla-cafe v0.1.1
npm i vanilla-cafeCreate a store
import { createStore } from "vanilla-cafe";
export const { set, sub, get } = createStore({
count: 0
})Update states
import { set, sub, get } from '../store';
function increment(){
set.count(p => p + 1)
}Subscribe to changes
let count = 0;
function handleCountChange(newValue){
count = newValue
}
const unsubscribe = sub.count(handleCountChange)Get the current state's value
const count = get.count()