observer-hoc-or-useobserver-hook

observer-hoc-or-useobserver-hook is a cursor rule for Cursor from holtwood/awesome-cursorrules-zh. It costs 0 tokens per session (676 once invoked), scanned A, original, MIT.

Guidance for making React components respond to changes in MobX observable data by wrapping them with an observer or using the useObserver Hook.

In plain words
What is it for?
Use it when displaying or editing MobX store data in React components, including cases where only part of a component should update.
Why use it?
Without this connection, a component may not update when the MobX data it displays changes.

Cursor rule for Cursor

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

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is import { useStore } from '../stores';.

Good fit Use it when displaying or editing MobX store data in React components, including cases where only part of a component should update.

Compare 6 cursor rules from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/holtwood/awesome-cursorrules-zh
agentmods
npx agentmods add rules/holtwood/awesome-cursorrules-zh/observer-hoc-or-useobserver-hook

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 observer-hoc-or-useobserver-hook

README.md
[![agentmods](https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/observer-hoc-or-useobserver-hook/github.svg)](https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/observer-hoc-or-useobserver-hook)
Your own site
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/observer-hoc-or-useobserver-hook"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/observer-hoc-or-useobserver-hook/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 observer-hoc-or-useobserver-hook

Your own site · 80×15
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/observer-hoc-or-useobserver-hook"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/observer-hoc-or-useobserver-hook.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 676 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.00676
Opus 5 $0.00000 $0.00338
Sonnet 5 $0.00000 $0.00135
Haiku 4.5 $0.00000 $0.00068

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

Security

Grade A, and why

observer-hoc-or-useobserver-hook 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 7d 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/observer-hoc-or-useobserver-hook.mdc · 61 lines

What it actually says

  • 对响应式组件使用 observer HOC 或 useObserver hook
    • observer HOC(高阶组件)
      • observermobx-react-lite 库提供的一个高阶组件,用于包裹 React 函数式组件或类组件,使其能够响应 MobX 状态的变化。
      • 当被包裹组件中使用的任何可观察数据发生变化时,observer 会触发组件的重新渲染。
      • 示例:
        import React from 'react';
        import { observer } from 'mobx-react-lite';
        import { useStore } from '../stores';
        
        const UserProfile = observer(() => {
          const { userStore } = useStore();
        
          return (
            <div>
              <h1>{userStore.name}</h1>
              <p>Email: {userStore.email}</p>
              <button onClick={() => userStore.updateName('Jane Doe')}>Update Name</button>
            </div>
          );
        });
        
        export default UserProfile;
        
    • useObserver Hook
      • useObservermobx-react-lite 提供的另一个选择,它是一个 React Hook,允许你在函数式组件的内部定义一个响应式渲染块。
      • 它适用于需要更细粒度控制渲染,或者只希望组件的某个部分响应 MobX 状态变化的场景。
      • 示例:
        import React from 'react';
        import { useObserver } from 'mobx-react-lite';
        import { useStore } from '../stores';
        
        const ProductDisplay = ({ productId }) => {
          const { productStore } = useStore();
        
          return useObserver(() => {
            const product = productStore.getProductById(productId);
            if (!product) return <div>Loading...</div>;
        
            return (
              <div>
                <h2>{product.name}</h2>
                <p>Price: ${product.price}</p>
                <p>Stock: {product.stock}</p>
              </div>
            );
          });
        };
        
        export default ProductDisplay;
        
    • 选择建议
      • 优先使用 observer HOC:对于大多数情况,直接使用 observer HOC 包裹整个函数式组件是更简洁和推荐的做法。它会自动处理组件内部所有可观察数据的响应式更新。
      • 在特定场景使用 useObserver Hook:当你需要在一个组件中,只有部分 UI 响应 MobX 状态变化,或者需要将响应式逻辑封装在自定义 Hook 中时,useObserver 提供了更大的灵活性。
      • 性能:两者在性能上都非常高效,因为 mobx-react-lite 实现了精确的响应式更新,只在实际观察到的数据发生变化时才触发渲染。
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. 7d ago First seen · 61 lines · 0 tokens per session scan A 34d140f3fca3

Subscribe to this mod's changes

observer-hoc-or-useobserver-hook 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 676 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.