All Projects → marshalYuan → east-store

marshalYuan / east-store

Licence: MIT license
east-store is a state manager with easiest api that based hooks and immer.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to east-store

react-immer
No nonsense state management with Immer and React hooks
Stars: ✭ 13 (-27.78%)
Mutual labels:  state-management, immer, react-hooks
Easy Peasy
Vegetarian friendly state for React
Stars: ✭ 4,525 (+25038.89%)
Mutual labels:  state-management, immer, react-hooks
Constate
React Context + State
Stars: ✭ 3,519 (+19450%)
Mutual labels:  state-management, react-hooks
react-immer-hooks
Easy immutability in React Hooks with Immer.
Stars: ✭ 45 (+150%)
Mutual labels:  immer, react-hooks
nstate
A simple but powerful react state management library with low mind burden
Stars: ✭ 11 (-38.89%)
Mutual labels:  state-management, immer
react-store
A library for better state management in react hooks world
Stars: ✭ 34 (+88.89%)
Mutual labels:  state-management, react-hooks
use-simple-store
🏬 Simple state management using React Hook
Stars: ✭ 21 (+16.67%)
Mutual labels:  state-management, react-hooks
quick-redux
helper functions to make redux and react development quicker
Stars: ✭ 61 (+238.89%)
Mutual labels:  state-management, immer
use-query-string
🆙 A React hook that serializes state into the URL query string
Stars: ✭ 50 (+177.78%)
Mutual labels:  state-management, react-hooks
use-state-machine
Use Finite State Machines with React Hooks
Stars: ✭ 28 (+55.56%)
Mutual labels:  state-management, react-hooks
react-mlyn
react bindings to mlyn
Stars: ✭ 19 (+5.56%)
Mutual labels:  state-management, react-hooks
atomic-state
A decentralized state management library for React
Stars: ✭ 54 (+200%)
Mutual labels:  state-management, react-hooks
hookstore
Hook based and lightweight centralized state management for React.
Stars: ✭ 28 (+55.56%)
Mutual labels:  state-management, react-hooks
jedisdb
redis like key-value state management solution for React
Stars: ✭ 13 (-27.78%)
Mutual labels:  state-management, react-hooks
react-without-redux
React State Management without Redux
Stars: ✭ 33 (+83.33%)
Mutual labels:  state-management, react-hooks
rematch
The Redux Framework
Stars: ✭ 8,340 (+46233.33%)
Mutual labels:  state-management, immer
use-app-state
🌏 useAppState() hook. that global version of setState() built on Context.
Stars: ✭ 65 (+261.11%)
Mutual labels:  state-management, react-hooks
concave
🧐 Lens-like state management (for React).
Stars: ✭ 13 (-27.78%)
Mutual labels:  state-management, react-hooks
rex-state
Convert hooks into shared states between React components
Stars: ✭ 32 (+77.78%)
Mutual labels:  state-management, react-hooks
niue
A tiny shared state and event library for React
Stars: ✭ 17 (-5.56%)
Mutual labels:  state-management, react-hooks

east-store

east-store is a state manager with easiest api that based hooks and immer.

npm MIT License

install

npm install east-store

features

  • easy usage, just one api createStore
  • immutale data based immer
  • friendly typescript support, no need more type declarations
  • use react-hooks, why not?

usage

import { createStore } from 'east-store'

const AtomicStore = createStore(0, {
    increase: () => count => count + 1,
    decrease: n => count => count - n
})

const Counter: React.FC = () => {
    const [count, action] = AtomicStore.useStore()
    const handleDecrease = () => {
        action.decrease(3)
    }
    return (
        <div>
            <span>{count}</span>
            <button id="increase-btn" onClick={action.increase}>
                increase
            </button>
            <button id="decrease-btn" onClick={handleDecrease}>
                decrease
            </button>
        </div>
    )
}

Of course, you can use object as initial state

const amy = {
    name: 'Amy',
    total: 130,
    score: { math: 60, english: 70 }
}
const buildStudentStore = (student: typeof amy) =>
    createStore(student, {
        modify: (subject: 'math' | 'english', score: number) => student => {
            student.score[subject] = score
            student.total = student.score.math + student.score.english
        }
    })

const amyScore = buildStudentStore(amy)

const [state, actions] = amyScore.useStore()

So, async operation is also supported

async function fetchCount(): number {
    return await fetch('/path')
}

const AtomicStore = createStore(0, {
    increase: () => count => count + 1,
    getRemote: () => async (_) => {
        return await fetchCount()
    }
})

Api

createStore(initial, actions, options)
des type
initial initial state primitive type
object
Map, Set
actions actions for state `(payload) => (state) => void
options other options persist: boolean or Storage, default false
set true if you want this state been persisted
and set custom storage implementation with set, get is also valid
* persistence means shared
useStore(selector?, compareFn?)
des type
selector selector function (state) => state.items
compareFn compare function,default shallow (prev, curr) => boolean
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].