0.0.14 • Published 2 years ago

react-tiny-store v0.0.14

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

An easier way to share state between React Components

Installing

Using npm:

npm install react-tiny-store --save

Using yarn:

yarn add react-tiny-store --save

Example

Store

import { createStore } from 'react-tiny-store'

const useCounterStore = createStore({count: 1, base: 0})

function Component() {
    const [state, setState] = useCounterStore()
    return (
        <button
            onClick={() => setState({ count: state.count + 1 })} // you can only set partial state
        >{`count: ${state.base + state.count}`}</button>
    )
}

Reactive Store

import { createReactiveStore } from "react-tiny-store"

const useReactiveStore = createReactiveStore({
    counter: {
        count: 1 
    } 
})

function Component() {
    const state = useReactiveStore()
    return (
        <button 
            onClick={() => state.counter.count ++}
            >{`count: ${state.counter.count}`}</button>
    )
}

useReactive

import { useReactive } from "react-tiny-store"

function Component() {
    const state = useReactive({
        counter: {
            count: 1
        }
    })
    return (
        <button 
            onClick={() => state.counter.count ++}
            >{`count: ${state.counter.count}`}</button>
    )
}
0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago