Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simpler-state

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simpler-state

The simplest app state management for React

  • 2.0.0-rc.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

SimpleR State

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)
  • Built-in developer tools (Inspector, global reset)
  • Full TypeScript support with simple types
  • Made specifically for React, and built on React Hooks
  • Fully supports React 18 Concurrent Mode
  • Several times faster than context+reducer solution
  • Tiny footprint, just around 2 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

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

This project has enabled GitHub Discussions. Please feel free to post any questions/suggestions there. For issues, please report them here.

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.

Keywords

FAQs

Package last updated on 10 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc