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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-sstate

v1.1.0

Published

React wrapper for using Sstate with React

Readme

react-sstate

react-sstate is a small wrapper for the Sstate library using React's context API. This library provides two components: <SstateProvider /> and <SstateConsumer />.

Changelog

| Version | Changes | | ------- | --------------------------- | | 0.1.0 | Initial version of react-sstate | | 0.2.0 | Improved setSstate and getSstate | | 0.2.1 | Fixed the publishing of the component | | 0.2.2 | Fixed an issue with providing the right path for getSstate | | 0.2.3 | Fixed an issue with providing the right path for setSstate | | 1.0.0 | Modified the SstateConsumer to unsubscribe on unmounting and removed the subscriptionId (based on the 1.0.0 version of Sstate) | | 1.0.1 | Fixed typo in the readme | | 1.0.2 | Updated lodash version due to vulnerability. Moved to Github | | 1.1.0 | Added execSstate so using actions becomes simple |

Example

App.js

import React, { Component } from 'react';
import { SstateProvider } from 'react-sstate';
import { Sstate } from 'sstate';

import FoodCart from './FoodCart';

const FoodStore = new Sstate({
    bread: { 
        baguette: 4, 
        wholeWeat: 3 
    }, 
    fruit: { 
        apples: 0.5, 
        bananas: 1 
    },
    startSync: null,
    completedSync: null
}, {
    incrementApples: (setSstate, sstate, args) => {
        setSstate('fruit.apples', sstate.fruit.apples + 1);
    },
    doubleApples: (setSstate, sstate, args) => {
        setSstate('fruit.apples', sstate.fruit.apples * 2);
    },
    persist: (setSstate, sstate, args) => {
        setSstate('startSync', args);
        axios.post('/api/fruitStore', state).then(() => {
            setSstate('completedSync', Date.now());
        });
    }
});

class App extends Component {
    render() {
        return <SstateProvider store={FoodStore}>
            <FoodCart />
        </SstateProvider>
    }
}

FoodCart.js

import React, { Component } from 'react';
import { SstateConsumer } from 'react-sstate';

class FoodCart extends Component {
    render() {
        const { 
            sstate, // Last state
            setSstate, // Method to set/update the state
            getSstate,  // Method to retrieve the current/part of the state
            execSstate // Method to execute (prefdined) actions on the store
        } = this.props;
        
        // You can access other state properties by specifying the path.
        const baguetteCount = getSstate('bread.baguette');

        // You can set other state properties as well, but the component
        // is not re-rendered as these properties are not watched.
        setSstate('bread.baguette', 5);

        // If setSstate is called without a reference, it will set the state
        // for the watched value. In this example 'fruit.bananas'
        setSstate(10)

        return (
            <>
                <p>Apple count: {sstate.next} (was {sstate.previous} before)</p>
                <p>Baguette count: {baguetteCount}</p>
                <button onClick={execSstate.bind(this, 'incrementApples')}>Add apple</button>
                <button onClick={execSstate.bind(this, 'doubleApples')}>Double apples</button>
                <button onClick={() => execSstate('persist', Date.now())}>Persist store</button>
            </>
        );
    }

}

export default const WrappedFoodCart = () => {
    return <SstateConsumer path={'fruit.apples'}><FoodCart /></SstateConsumer>;
}

Props provided by <SstateConsumer /> to its children

sstate

This is the initial/current state of the property that was provided by passing the path on the <SstateConsumer />.

getSstate

This is a method to get the latest state of the watched property, or other properties on the Sstate store.

// Retrieves the watched property provided by the passed path on the SstateConsumer
getSstate() 

// With a given path, you can access all other properties on the Sstate store.
getSstate( path ) 

setSstate

This is a method for modifying the watched property, or other properties on the Sstate store.

// Updates the watched value
setSstate( newValue ) 

// With path as the first property, you can also modify other properties
setSstate( path, newValue ) 

execSstate

This is a method for executing predefined actions on the store with the possibility to pass in arguments.

// Executes a action
execSstate('actionName', optionalArguments);