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

react-mug

v0.10.0

Published

下一代 React 状态库,为极致的体验而生 ✨ / Next-generation React state lib. Born for optimal experience ✨

Readme

React Mug

概要  •  特性  •  安装  •  指南  •  API  •  许可  •  赞助

中文  •  English

概要

下一代 React 状态库,为极致的体验而生 —— 极致的既是用户体验,也是开发者体验。

特性

好写

秉承函数式内核,但化繁为简:

// CountState.ts
import { construction, upon } from 'react-mug';

const { r, w } = upon<number>({
  [construction]: 0,
});

export const get = r((count) => count);

export const increase = w((count, delta: number) => count + delta);

透传值的读操作,进一步化简:

// CountState.ts

export const get = r();

好调用

所有状态操作既可以直接调用:

const count = get();

increase(1);

也可以在 React 组件结合调用:

// Count.tsx
import { useR } from 'react-mug';
import { get, increase } from './CountState';

export function Count() {
  const count = useR(get);
  return <button onClick={() => increase(1)}>Count: {count}</button>;
}

好复用

所有操作均可以借助函数态相互复用:

// CountState.ts

export const addOne = w((count) => increase(count, 1));

好读

不必深入函数体就能看明白读写范围:

// CountState.ts

export const increase = w((count, delta: number) => ...);

好测

直接以函数态轻松测试操作:

// CountState.test.ts
import { increase } from './CountState';

describe('increase', () => {
  test('adds up count and delta', () => {
    expect(increase(1, 2)).toBe(3);
  });
});

可组合

参见下方指南。

可分隔

参见下方指南。

可异步

直接以普通的异步函数定义异步操作:

// CountState.ts

export const set = w();

export const query = async () => {
  const { data: count } = await fetch('/api/count').then((res) => res.json());
  set(count);
};

安装

npm i react-mug

指南

管理单个状态 组合多个状态 分隔通用特质

API

参见 src/index

许可

Apache 2.0(免费商用)。

赞助

喜欢就赞助一下吧!

(国内) (海外)


返回顶部