1.2.1 • Published 1 year ago

simpler-state v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

npm build coverage license

SimpleR State is an ultra-lightweight library that provides the simplest state management for React.

  • Minimalist API; no complicated concepts or boilerplate
  • Use plain functions to update state (including async)
  • Largely unopinionated with flexible syntax
  • Extremely simple to unit test state logic
  • Highly extensible with plug-ins (e.g. persistence, dev tools)
  • Full TypeScript support with uncomplicated types
  • Made specifically for React, and built on React Hooks
  • Multiple times faster than context/reducer solution
  • It's tiny, just around 1 KB (minified + gzipped)

Get all these benefits with one dependency install:

npm install simpler-state

Two Easy Steps!

Step 1: Create an entity (shared state) and actions (updater functions)

// counter.js

import { entity } from 'simpler-state'

export const counter = entity(0)

export const reset = () => {
  counter.set(0)
}

export const increment = by => {
  counter.set(value => value + by)  
  // --OR-->  counter.set(counter.get() + by)  
}

Step 2: Use the entity in your components with hooks

import { counter, increment, reset } from 'counter'

const CounterView = () => {
  const count = counter.use()
  // --OR-->  const count = useEntity(counter)

  return (
    <>
      <div>{count}</div>

      <button onClick={() => increment(1)}> + </button> 
      <button onClick={reset}> Reset </button>
    </>
  )
}

It's that simple! But the library can do a lot more, so check out the docs website.

Documentation

Learn more about what you can do with SimpleR State at simpler-state.js.org.

Feedback

I have opened a Request For Comments (here) on GitHub. Your comments and suggestions would be greatly appreciated.

And if you like this library, the concept, and its simplicity, please give it a star on the GitHub repo to let me know. 😀

Prior Art

This library is an evolution of the already production-proven react-entities that I also wrote. It shares the same stable core, but with a very different API.

1.2.2-rc.1

1 year ago

1.2.1

1 year ago

2.0.0-rc.3

1 year ago

2.0.0-rc.4

1 year ago

2.0.0-rc.5

1 year ago

2.0.0-rc.11

1 year ago

2.0.0-rc.12

1 year ago

2.0.0-rc.10

1 year ago

2.0.0-rc.6

1 year ago

2.0.0-rc.7

1 year ago

2.0.0-rc.8

1 year ago

2.0.0-rc.9

1 year ago

2.0.0-rc.2

1 year ago

2.0.0-rc.1

2 years ago

2.0.0-pre.5

2 years ago

2.0.0-pre.7

2 years ago

2.0.0-pre.6

2 years ago

2.0.0-pre.1

2 years ago

2.0.0-pre.4

2 years ago

2.0.0-pre.3

2 years ago

2.0.0-pre.2

2 years ago

1.2.0

2 years ago

1.2.0-rc.1

2 years ago

1.2.0-rc.0

2 years ago

1.1.0

2 years ago

1.1.0-rc.1

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.2-pre.1

3 years ago

1.0.1-pre.1

3 years ago

1.0.1-pre.0

3 years ago

1.0.2-pre.0

3 years ago

1.0.0

3 years ago

1.0.0-rc.10

3 years ago

1.0.0-rc.9-pre.3

3 years ago

1.0.0-rc.9

3 years ago

1.0.0-rc.8

3 years ago

1.0.0-rc.8-pre.1

3 years ago

1.0.0-rc.9-pre.1

3 years ago

1.0.0-rc.9-pre.0

3 years ago

1.0.0-rc.9-pre.2

3 years ago

1.0.0-rc.8-pre.0

3 years ago

1.0.0-rc.7

3 years ago

1.0.0-rc.5

3 years ago

1.0.0-rc.6

3 years ago

1.0.0-rc.4

3 years ago

1.0.0-rc.3

3 years ago

1.0.0-rc.1

3 years ago

1.0.0-rc.2

3 years ago

1.0.0-rc.0

3 years ago

1.0.0-beta.6

3 years ago

1.0.0-beta.7

3 years ago

1.0.0-beta.2

3 years ago

1.0.0-beta.3

3 years ago

1.0.0-beta.4

3 years ago

1.0.0-beta.5

3 years ago

1.0.0-beta.1

3 years ago

1.0.0-beta.0

3 years ago