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

@little-saga/use-saga

v0.8.0

Published

Run little-saga inside a React component using React hooks.

Readme

NPM Package

@little-saga/use-saga

使用 React hooks 特性 在一个组件的生命周期内运行 little-saga。

该类库提供了一个函数 useSaga,用于在一个 React 函数组件的生命周期内运行 saga。useSaga 像是 useReducer 的增强版,useSaga 在创建 redux-like 状态容器的同时会启动我们所提供的 saga;当组件卸载时,saga 会自动结束运行。

注意事项:

  • useSaga 是一个 React hook,使用 useSaga 需要符合 hook 的书写规则。
  • 该类库只能与 little-saga 一起使用,且要求 React 为支持 hooks 的版本(>= 16.7).

使用方式

import useSaga from '@little-saga/use-saga'

function OurReactComponent() {
  const [state, dispatch] = useSaga(options)

  // ... 其他代码 ...
}

参数 options 是一个对象,具体字段如下:

| 字段 | 类型 | 默认值 | 含义 | | --------------- | ----------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------- | | saga | 生成器函数 | 必须字段 | 所要执行的 saga 函数 | | args | 数组 | [] | 启动 saga 函数时所使用的参数 | | reducer | 函数 | x => x | 指定 state 如何响应 actions | | initialState | 任意值 | undefined | 初始状态 | | initialAction | 任意合法的 action | undefined | 创建状态容器时用于初始化状态的 action详见 useReducer 文档 | | customEnv | 任意值 | undefined | 指定 运行运行环境对象中的额外字段 详见 runSaga#options.customEnv | | taskContext | 普通对象 | undefined | root task 的初始 context 详见 runSaga#options.taskContext |

useSaga 的返回值useReducer 的返回值相同,一般我们可以用数组解构的方式将其赋值给变量 statedispatchstate 表示当前状态容器的最新状态,dispatch 用于向状态容器 / saga 运行时派发 action。

使用举例