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 🙏

© 2024 – Pkg Stats / Ryan Hefner

sbox-react

v2.0.0

Published

the easiest and simple solution for react scalable state management

Downloads

19

Readme

sbox

the easiest and simple solution for react scalable state management

Installation

npm install sbox-react

first create store

all what you need is on the createState function

import createState from "sbox-react";

const state = { msg: "hi", values: { one: "one", two: "two" } };

// all what you need is return a partial from the state to update it
const store = createState(state, (currentState) => ({

  open: () => ({ msg: "time - " + Date.now() }),
  close: async (e) => {
    const fetch = await ...
    //some workd here
    //

    // it's gonna merge the state and the object you return so you don't have to worry about anything

    return { value: { one : fetch} };
  },
}));

and use it on your components

function Value = () => {
    // state is you current state with latest update
  const value = store.useStore((state) => state.s);
  return <h1>{value} around here ...</h1>;
}

how to use methods

function Value = () => {
  const value = store.useStore((state) => state.s);


  return <h1 onClick={()=> store.open()} >
            click me to update it ... {value}
        </h1>;
}

sUpdate

easy function to update state, get an object as parameter and merge it with the state

function Value = () => {
    // state is you current state with latest update
  const value = store.useStore((state) => state.s);

  return <h1 onClick={()=>
                        store.sUpdate({s :"changed by sUpdate function"})
                    }>
            click me to update it ... {value}
        </h1>;
}

async action

just return a part of the state from the action and it's done

const store = createState(state, (currentState) => ({

  close: async (e) => {
    const fetch = await ...
    //some workd here
    //

    // it's gonna merge the state and the object you return so you don't have to worry about anything

    return { value: { one : fetch} };
  },
}));

Read from state in actions

const store = createState(state, (currentState) => ({
  set: (e) => {
    return { value: { one: currentState.value.one * 2 } };
  },
}));

Why sbox over all ?

  • Simple and un-opinionated
  • Makes hooks the primary means of consuming state
  • Doesn't wrap your app in context providers
  • Can inform components transiently (without causing render)
  • i made it :)