Reim.js
:thinking: Why another state library?
:metal: Update state by simply mutating it, thanks to immer
:closed_lock_with_key: Immutable state
:zap: Small, 6kb gzip + minified
:star2: Typing support for Typescript & Flow
:atom_symbol: Supports Redux Dev Tools
:book: How to use
$ yarn add reim react-reimThen use useReim just like other React hooks :
import React from 'react'
import reim from 'reim'
import {useReim} from 'react-reim'
function Counter() {
const [count, {increment}] = useReim(10, {
actions: {
increment: () => state => state++,
decrement: () => state => state--
}
})
return (
<div>
<button onClick={increment}>+</button>
<div id="count">{count}</div>
</div>
)
}or use <State/> for some cases:
Table of Contents
reim
reimreim(state | store, {actions?: Actions, name?: string})
reim(state | store, {actions?: Actions, name?: string})Returns a new Reim store.
An action is simple a function that returns a state updater.
For example:
Then just use it as a method:
filter(getter: {[name]: state => any} | state => any | keyof typeof state)
filter(getter: {[name]: state => any} | state => any | keyof typeof state)Gets current snapshot of store
subscribe(fn, {filter})
subscribe(fn, {filter})fn gets called on change. You can unsubscribe(fn) to stop subscription.
reim.snapshot()
reim.snapshot()Returns snapshot of all stores created
reim.stringify()
reim.stringify()Returns JSON.stringify-ed snapshot of all stores created, safe for injecting
reim.preload(snapshot)
reim.preload(snapshot)Used in client side for preloading states
react-reim
react-reim<State/>
<State/>initial
initialInitial value of the store. The store is resets if initial value is changed.
store
storeReceives a Reim store, initial is ignored if store is provided
actions
actionsSame as actions in reim()
filter
filterSame as filter in reim()
useReim(store | state, {filter, actions})
useReim(store | state, {filter, actions})Returns [snapshot, actions]
:heart: Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
:page_with_curl: License
MIT © IniZio
Last updated