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

state-radio-react

v1.0.6

Published

A react hook for working with state radio in react, a state management library that let's you tune to your application state like a radio set!

Downloads

30

Readme

State Radio 📻 - React

A state management library that let's you tune to your state channels via subscriptions and listen to state updates with fine tuned simplicity.

Here is a guide on how to use it specifically in react, spoiler, it's more performant than react context given react rerenders all your components on change if they share the same context provider, but here we only rerender the single component that depends on the changed state, very modular and fine grained way to work with state in whatever framework you use.

This might not be so much of performance upgrade for signal based frameworks which use signals or simillar reactive mechanisms to manage state, but for react sure it's a big difference, try it yourself for comparison, run the setup in example by cloning this repo, cd to example and install dependencies then run, and you will see something like this, you can then measure rerenders using profiler from react dev tools extension.

demo screenshot

💡Note: here we will only show react usage, for full usage of state radio state manager, please check the state radio docs

▶️ Installation

npm install state-radio-react

Usage In A React Project

-- step 1: create a file called store.js and import the library and intialize your initial states, you can also do more things here, like making some state hooks for your application say useAuth or subscribe to state changes if you want. For example:

import { StateRadio } from 'state-radio-react';

const { channels } = new StateRadio();

export const countChannel = channels.addChannel('count', 0);

export const abcChannel = channels.addChannel('abc', 'abc');

countChannel.subscribe((newCount) => {
  console.log('Count Changed to:', newCount);
});

abcChannel.subscribe((newState) => {
  console.log('ABC Changed to:', newState);
});

Notice that we exported our state channels so that we can use them else where in our application, you don't need to wrap your app with any provider or so.

-- step 2: use in any of your components by importing any of the channels you created in step 1 and the useChannel hook to allow you consume the channel in react.

import { countChannel } from '../store';
import { useChannel } from 'state-radio-react';

export default function Counter() {
  const [count, setCount] = useChannel(countChannel);

  return (
    <div>
      <h1>{count}</h1>
      <button onClick={() => setCount(count + 1)}>add +1</button>
    </div>
  );
}

That's it, for more things you can do with this new found power, check the detailed documentation here state radio docs

That's it, play around, enjoy the radio show!!!

Contributing

If you find issues or have ideas for improvements, please open an issue or submit a pull request or contact author at [email protected]

This project is licensed under the MIT License.