mobx-react-lite-usage

mobx-react-lite-usage is a cursor rule for coding agents from holtwood/awesome-cursorrules-zh. It costs 0 tokens per session (556 once invoked), scanned A, original, MIT.

A set of rules for connecting MobX to React function components through mobx-react-lite, a library that makes components observe MobX state.

In plain words
What is it for?
Use it when building MobX-backed React lists and components with observer or useObserver.
Why use it?
It helps components rerender when the data they use changes while avoiding updates caused by unrelated store data.

Cursor rule

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.

agentmods
npx agentmods add rules/holtwood/awesome-cursorrules-zh/mobx-react-lite-usage
Clone the repo
git clone --depth 1 https://github.com/holtwood/awesome-cursorrules-zh

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-react-lite-usage

README.md
[![agentmods](https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/mobx-react-lite-usage.svg)](https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/mobx-react-lite-usage)
Your own site
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/mobx-react-lite-usage"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/mobx-react-lite-usage.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 556 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00000 $0.00556
Opus 5 $0.00000 $0.00278
Sonnet 5 $0.00000 $0.00111
Haiku 4.5 $0.00000 $0.00056

Measured yesterday against content hash 9dfbf6beaa0b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

mobx-react-lite-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 yesterday.

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-react-lite-usage.mdc · 54 lines

What it actually says

  • 使用 MobX-react-lite 以在函数式组件中获得最佳性能
    • observer HOC 或 useObserver Hook
      • 对于函数式组件,推荐使用 mobx-react-lite 提供的 observer 高阶组件(HOC)或 useObserver Hook 来包裹组件,使其能够响应 MobX 状态的变化。
      • observer HOC 示例:
        import React from 'react';
        import { observer } from 'mobx-react-lite';
        import { useStore } from '../stores';
        
        const TodoList = observer(() => {
          const { todoStore } = useStore();
        
          return (
            <div>
              {todoStore.todos.map(todo => (
                <div key={todo.id}>{todo.text}</div>
              ))}
            </div>
          );
        });
        
        export default TodoList;
        
      • useObserver Hook 示例(适用于需要更细粒度控制渲染的场景):
        import React from 'react';
        import { useObserver } from 'mobx-react-lite';
        import { useStore } from '../stores';
        
        const TodoItem = ({ todo }) => {
          return useObserver(() => (
            <li>
              {todo.text}
              <button onClick={() => todo.toggleCompleted()}>
                {todo.completed ? 'Mark Incomplete' : 'Mark Complete'}
              </button>
            </li>
          ));
        };
        
        export default TodoItem;
        
    • 性能优化
      • mobx-react-lite 针对函数式组件进行了优化,只在组件实际观察到的数据发生变化时才重新渲染组件,从而最大限度地减少不必要的渲染。
      • 避免在 observer 组件内部解构 MobX store 的可观察属性,这可能导致组件观察到整个 store 而不是特定属性,从而触发不必要的重新渲染。应在组件内部访问具体属性。
    • 与 Hooks 结合使用
      • mobx-react-lite 与 React Hooks 完美结合,可以在 observer 组件内部自由使用 useState, useEffect, useContext 等 Hooks。
    • 轻量级
      • mobx-react-lite 是一个轻量级的包,只提供了 MobX 与 React 函数式组件集成的核心功能,没有额外的负担。
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. yesterday First seen · 54 lines · 0 tokens per session scan A 9dfbf6beaa0b

Subscribe to this mod's changes

mobx-react-lite-usage is a cursor rule published in the GitHub repository holtwood/awesome-cursorrules-zh (232 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 556 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.