npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nextlevelcoder/simplestate

v0.0.17

Published

A simple state sharing class for React. Use instead of MobX or Redux.

Readme

simplestate

Easy to learn and use replacement for MobX and Redux in React projects.

Installation

To install SimpleState in your project, run:

npm install @nextlevelcoder/simplestate

Usage

SimpleState can be used in Functional and Class React Components. The module includes a global SimpleState instance as simpleState, in addition to the SimpleState class.

SimpleState can also be subscribed to by functions, which can be used to modify derivative state.

Functional Components

Access the shared state "hello" using the variable "hello". Just as with the standard useState, you can pass a default value (true in the example).

import { simpleState } from '@nextlevelcoder/simplestate';

function MyComponent(props) {
    const [hello, setHello] = simpleState.useState('hello', true);
    . . . 
}

To set state you can use the returned set function (setHello) or SimpleState.setState as demonstrated in the Class Component section.

Class Components

Access the shared state "hello" as "this.state.hello".

import { simpleState } from '@nextlevelcoder/simplestate';

class MyComponent extends Component {
    componentWillMount() {
        simpleState.bindState(this, 'hello');
    }
    componentWillUnmount() {
        simpleState.unbindState(this);
        // To unbind just hello, use simpleState.unbindState(this, 'hello');
    }
    . . .
}

To bind multiple states, pass an array as the second param instead of a string:

import { simpleState } from '@nextlevelcoder/simplestate';

class MyComponent extends Component {
    componentWillMount() {
        simpleState.bindState(this, ['connected', 'latency']);
    }
    componentWillUnmount() {
        simpleState.unbindState(this);
        // To unbind multiple states (but not all states) call simpleState.unbindState(this, ['connected', 'latency]);
    }
    . . .
}

If you want to group related states in a single object on your state, you can pass an optional third parameter with the group name:

class MyComponent extends Component {
    componentWillMount() {
        // Access with this.state.sharedState.hello
        simpleState.bindState(this, 'hello', 'sharedState');
        // Access with this.state.networkState.online and this.state.networkState.latency
        simpleState.bindState(this, ['online', 'latency'], 'networkState');
    }
    componentWillUnmount() {
        // Group name isn't required to unbind, even when listing states.
        simpleState.unbindState(this);
    }
    . . .
}

To set state from a class component, you can call setState the same way you would for a component's state:

simpleState.setState({ hello: false });

Methods

import { simpleState } from '@nextlevelcoder/simplestate';

const mySubscriber = (state, value)=>{
    simpleState.setState('derivedState', value*2);
};

simpleState.subscribe('originalState', mySubscriber);
. . .

// If we ever want to stop updating derivedState
simpleState.unsubscibe('originalState', mySubscriber);

Multiple SimpleStates

SimpleState is a class you can instantiate as many times as you'd like.

SimpleStateMap

The best way to use multiple SimpleStates is with a SimpleStateMap. This is just a DefaultMap with a helper that creates new SimpleStates as its default value.

A global instance of SimpleStateMap can be imported as used as follows:

import { simpleStateMap } from '@nextlevelcoder/simplestate';

const accountState = simpleStateMap.getState('account');
const shoppingCartState = simpleStateMap.getState('shoppingCart');

Then you can use each SimpleState the way you used the global simpleState instance in the example above.

simpleStateMap is a global instance of SimpleStateMap. You can import and instantiate multiple SimpleStateMaps if you really want to complicate your code.

import { SimpleStateMap } from '@nextlevelcoder/simplestate';

const accountState = new SimpleStateMap();
const shoppingCartState = new SimpleStateMap();

// Export your manually create SimpleStateMaps to use them in other files.
export { accountState, shoppingCartState };

Manually

You can also declare and export multiple SimpleStates in a file shared by your components.

import { SimpleState } from '@nextlevelcoder/simplestate';

const accountState = new SimpleState();
const shoppingCartState = new SimpleState();

// Export your SimpleStates to use them in other files.
export { accountState, shoppingCartState };

Then just import your instances in the files that need to use them.