0.0.14 • Published 3 years ago

react-tiny-store v0.0.14

Weekly downloads
-
License
MIT
Repository
-
Last release
3 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

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago