mobx-reaction-usage

mobx-reaction-usage is a cursor rule for Cursor from holtwood/awesome-cursorrules-zh. It costs 0 tokens per session (648 once invoked), scanned A, original, MIT.

Guidance for using MobX reaction, a mechanism that runs a side effect when selected observable data changes.

In plain words
What is it for?
Use it to load data after an ID changes, subscribe to services, write to local storage, or log state changes.
Why use it?
It prevents unrelated state changes from triggering work and lets you control whether the effect runs during startup.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it to load data after an ID changes, subscribe to services, write to local storage, or log state changes.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/holtwood/awesome-cursorrules-zh/mobx-reaction-usage
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/holtwood/awesome-cursorrules-zh

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for mobx-reaction-usage

README.md
[![agentmods](https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/mobx-reaction-usage/github.svg)](https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/mobx-reaction-usage)
Your own site
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/mobx-reaction-usage"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/mobx-reaction-usage/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for mobx-reaction-usage

Your own site · 80×15
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/mobx-reaction-usage"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/mobx-reaction-usage.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 648 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00648
Opus 5 $0.00000 $0.00324
Sonnet 5 $0.00000 $0.00130
Haiku 4.5 $0.00000 $0.00065

Measured 6d ago against content hash c5fb0c1b5107, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

mobx-reaction-usage scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/rules/frontend/react/mobx/mobx-reaction-usage.mdc · 57 lines

What it actually says

  • 使用 reaction 处理基于可观察变化的副作用
    • reaction 的作用
      • reaction 是 MobX 提供的一种副作用处理机制,它接受两个函数作为参数:第一个函数(data 函数)跟踪其内部使用的可观察数据,并返回一个值;第二个函数(effect 函数)接收 data 函数的返回值,并在 data 函数返回的值发生变化时执行。
      • autorun 不同,reaction 允许你更精确地控制哪些数据变化会触发副作用,并且 effect 函数不会在初始化时立即运行。
    • 使用场景
      • 当你需要根据 MobX 状态的变化执行一些副作用,例如:
        • 异步数据加载(例如,当用户 ID 变化时加载用户数据)。
        • 订阅外部服务或事件。
        • 写入本地存储(localStorage)。
        • 打印日志。
    • 示例
      import { makeObservable, observable, action, reaction } from 'mobx';
      
      class UserStore {
        @observable userId = 0;
        @observable userData = null;
      
        constructor() {
          makeObservable(this);
          reaction(
            () => this.userId, // data 函数:跟踪 userId
            async (userId) => {
              if (userId > 0) {
                console.log(`Fetching user data for userId: ${userId}`);
                // 模拟异步请求
                this.userData = await new Promise(resolve => 
                  setTimeout(() => resolve({ id: userId, name: `User ${userId}` }), 500)
                );
              } else {
                this.userData = null;
              }
            }, 
            { fireImmediately: true } // 立即执行一次 effect 函数
          );
        }
      
        @action
        setUserId(id: number) {
          this.userId = id;
        }
      }
      
      const userStore = new UserStore();
      userStore.setUserId(1); // 这将触发 reaction,加载用户数据
      // userStore.setUserId(2); // 再次触发 reaction
      
    • 最佳实践
      • 尽量在 store 内部使用 reaction 来处理与状态相关的副作用,保持组件的纯粹性。
      • 避免在 data 函数中执行耗时操作,因为它会频繁运行。
      • 如果副作用需要清理(例如,取消订阅),reaction 函数会返回一个清理函数,可以在组件卸载时调用它。
      • 对于简单的、不依赖于特定数据变化的副作用,可以考虑使用 autorun
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 57 lines · 0 tokens per session scan A c5fb0c1b5107

Subscribe to this mod's changes

mobx-reaction-usage is a cursor rule published in the GitHub repository holtwood/awesome-cursorrules-zh (233 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 648 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.