Skip to content
πŸ€” Handle logic in frontend
TypeScript JavaScript
Branch: master
Clone or download
Latest commit 5678c86 Sep 17, 2019

Reim Β·

πŸ€” Why another state library?

  • 🀘 Update state by simply mutating it, thanks to immer
  • πŸ” Immutable state
  • ⚑️ Small, 6kb gzip + minified
  • 🌟 Typing support for Typescript & Flow
  • βš›οΈ Supports Redux Dev Tools

πŸ“– How to use

$ yarn add reim react-reim

Then 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 (
      <button onClick={increment}>+</button>
      <div id="count">{count}</div>

or use <State/> for some cases:

import React from 'react'
import reim from 'reim'
import {State} from 'react-reim'

const Toggle = () => (
    actions={{toggle: () => state => !state}}
    {(visible, {toggle}) => (
      <button onClick={toggle}>{visible ? 'On' : 'Off'}</button>

Table of Contents


↑ Back to top

reim(state | store, {actions?: Actions, name?: string})

↑ Back to top

Returns a new Reim store.

An action is simple a function that returns a state updater.

For example:

const store = reim({count: 10}, {
  actions: {
    add: amount => state => {state.count += amount}

Then just use it as a method:

// before: {count: 10}


// after: {count: 15}

filter(getter: {[name]: state => any} | state => any | keyof typeof state)

Gets current snapshot of store

subscribe(fn, {filter})

fn gets called on change. You can unsubscribe(fn) to stop subscription.


↑ Back to top

Returns snapshot of all stores created

reim({abc: 133})

reim.snapshot() // -> {0: {abc: 133}}


↑ Back to top

Returns JSON.stringify-ed snapshot of all stores created, safe for injecting


↑ Back to top

Used in client side for preloading states

// Server side:
`<script>window.__PRELOAD_STATE__ = ${reim.stringify()}</script>`

// Client side:


↑ Back to top


↑ Back to top


↑ Back to top

Initial value of the store. The store is resets if initial value is changed.


↑ Back to top

Receives a Reim store, initial is ignored if store is provided


↑ Back to top

Same as actions in reim()


↑ Back to top

Same as filter in reim()

useReim(store | state, {filter, actions})

Returns [snapshot, actions]

❀️ Contributing

Please read for details on our code of conduct, and the process for submitting pull requests to us.

πŸ“ƒ License

MIT Β© IniZio

You can’t perform that action at this time.