writable-store
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Writable Store

Tiny tiny state management package inspired by Svelte stores.

Installation

$ npm i writable-store

Setup

Import writable and create a writable store with an initial state:

import { writable } from 'writable-store'
 
export const todoStore = writable([])

Import the store inside your component and subscribe to receive updated values:

import { todoStore } from './stores'
 
const $todos = todoStore.subscribe(todos => /* Do something... */)

You can use the value received after subscription to update component props, state etc...

To update the store with a new value:

todoStore.set(todos => /* New value... */)

To retreive the current store value:

todoStore.get() 

Remember to unsubscribe during cleanup / unmounting:

$todos.unsubscribe()

/writable-store/

    Package Sidebar

    Install

    npm i writable-store

    Weekly Downloads

    5

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    6.84 kB

    Total Files

    12

    Last publish

    Collaborators

    • anthonypenna