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

galactic-context

v3.0.0

Published

Easy, efficient state management with React Context

Downloads

35

Readme

Galactic Context

Easy, efficient state management with React Context.

NPM npm NPM

Install

npm i galactic-context

Motivation

If you're using Context for "global" state, you run the risk of rerendering your entire app each time you update a value in a provider. This is because each Provider is a component, and when it rerenders, all of it's children will also rerender.

You can also have complications if you have Provider state values that depend on each other. No Provider can easily access the Context values of it's children.

Context also has a lot of boilerplate that would be nice to reduce.

Galactic Context allows you to have a single "StateProvider" to store all of the values you would consider using "globally" across components in your app. It generates "value" and "setter" hooks for you, and when a "setter" hook gets called to update state, only the components consuming the "value" hooks will update (not your entire app).

Usage

createGalacticContext receives a single argument--an object corresponding to key value pairs, for which the resulting object will return setter hooks and getter hooks. The getter hooks will be named as "usePropertyName" and "useSetPropertyName".

createGalacContext also includes the StateProvider, which will use to wrap your app.

const {
  StateProvider,
  getters: { useCounter, useEmail },
  setters: { useSetCounter, useSetEmail },
} = createGalacticContext({
  counter: 0,
  email: "",
});

function App() {
  <StateProvider>
    <CounterComponent label="component 1" />
    <CounterComponent label="component 2" /> // Both CounterComponents will update
    when the setter for `useCounter` is called.
    <EmailComponent /> // EmailComponent WON'T rerender when the setter for
    `useCounter` is called. StateProvider won't cause rerenders at all.
  </StateProvider>;
}

function CounterComponent({ label }) {
  const counter = useCounter();
  const setCounter = useSetCounter();

  return (
    <div>
      <h1>{`${label}, ${counter}`}</h1>
      <button onClick={() => setCounter(counter + 1)}>Increment</button>
    </div>
  );
}

function EmailComponent() {
  const email = useEmail();
  const useSetEmail = useSetEmail();

  return <input onChange={(e) => setEmail(e.target.value)} value={email} />;
}

createGalacticContext will include StateContext in it's returned object, but it's unlikely you'll need it (you'd probably only want to use it in conjunction with RxJS). It includes the observers for all of the properties, the names of which match the object you passed to createGalacticContext.

Debugger

StateProvder accepts an options debug param.

You can pass it:

  1. * to console.log the key and new value of every setter that gets called.
  2. A regular expression to console.trace each setter call (good for tracking where state is being set from).
  3. A function that receives the key and new value of the setter.
return (
  <StateProvider
    debug={(key, newValue) => {
      if (key === "counter") {
        debugger;
      }
    }}
  >
    <App />
  </StateProvider>
);