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

azux

v0.0.4

Published

A small state management that is inspired on unstated-next

Downloads

33

Readme

Azux

A small state management that is inspired on unstated-next

Install

npm install --save azux

Example

import React, { useState } from "react";
import { useStore, Provider } from "azux";
import { render } from "react-dom";

function CounterStore(initial = 0) {
  const [count, setCount] = useState(initial);
  const decrement = () => setCount(count - 1);
  const increment = () => setCount(count + 1);
  return { count, decrement, increment };
}

function CounterDisplay() {
  const { count, increment, decrement } = useStore(CounterStore);
  return (
    <div>
      <button onClick={decrement}>-</button>
      <span>{count}</span>
      <button onClick={increment}>+</button>
    </div>
  );
}

function App() {
  return (
    <Provider store={CounterStore}>
      <CounterDisplay />
      <Provider store={CounterStore} initial={2}>
        <div>
          <div>
            <CounterDisplay />
          </div>
        </div>
      </Provider>
    </Provider>
  );
}

render(<App />, document.getElementById("root"));

API

Provider

Passing store and its initial state

<Provider store={CountStore} initial={0} />

Passing multiple stores and their initial states

<Provider
  store={{ CountStore, GreetingStore }}
  initial={{ CountStore: 0, GreetingStore: "World" }}
/>

Passing store tuples

<Provider
  store={[
    [CountStore, 0],
    [GreetingStore, "World"],
  ]}
/>

useStore()

Retrieve store api

function Component() {
  // this component will rerender whenever store api updated
  const { count, increment, decrement } = useStore(CounterStore);
}

Use selector to retrieve specific store prop

function Component() {
  // this component will rerender whenever count prop changed
  const count = useStore(CounterStore, (api) => api.count);
}

Advanced Usages

Composing stores

const CountStore = (initial) => {
  const [count, setCount] = useState(initial);
  return {
    count,
    increase() {
      setCount(count + 1);
    },
  };
};

const GreetingStore = (initial) => {
  const [name, setName] = useState(initial);
  return {
    name,
    updateName: setName,
  };
};

const MainStore = ({ name, count } = {}) => {
  // extend stores with initial values
  const counter = useStore(CountStore, count);
  const greeting = useStore(GreetingStore, name);
  return {
    ...counter,
    ...greeting,
  };
};