Official agent skill

React Rx Hook Audit

by sanity-io in sanity-io/sanity

Find react-rx hook call sites (useObservable, useSyncObservable, useObservablePromise) whose observable identity churns or that re-render more than needed, verify the suspicion at runtime, and…

OfficialMITAuto-check passedDevelopment

Install React Rx Hook Audit

skills CLI
$ npx skills add sanity-io/sanity --skill react-rx-hook-audit -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install sanity-io/sanity react-rx-hook-audit --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/sanity-io/sanity.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/react-rx-hook-audit .claude/skills/react-rx-hook-audit && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
react-rx-hook-audit
GitHub stars
6.4k
Token cost
~3k tokens
SKILL.md length
1,081 words
Files
1
Skills in repo
34
Repo updated
First seen
Licence
MIT

At a glance

Find react-rx hook call sites (useObservable, useSyncObservable, useObservablePromise) whose observable identity churns or that re-render more than needed, verify the suspicion at runtime, and…

  • Works in 2 steps: Add a temporary console.log('[rx:build]… → Drive the studio with Playwright in…
  • Writing a component
  • SKILL.md covers Start here, Find candidates, Count renders at runtime and Count subscriptions at runtime, plus 2 more sections
  • Calls rg, pnpm and npm; needs STUDIO_AUTH_TOKEN

What it does

React Rx Hook Audit is an agent skill from sanity-io/sanity, published by the product's own GitHub organization. Find react-rx hook call sites (useObservable, useSyncObservable, useObservablePromise) whose observable identity churns or that re-render more than needed, verify the suspicion at runtime, and refactor them to the useValuePreview pattern. Use when reviewing or writing a component or hook that calls these hooks, or when a re-render, loading flash or resubscribe storm is suspected.

Its SKILL.md is about 3k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Refactoring. It works with React. The repository describes itself as: Sanity Studio – Rapidly configure content workspaces powered by structured content. The licence is MIT.

When your agent uses it

  • Writing a component
  • Hook that calls these hooks
  • Resubscribe storm is suspected

Example prompts

  • “/react-rx-hook-audit”

Requirements

  • A credential in STUDIO_AUTH_TOKEN

Workflow steps

2 steps, taken from the first numbered list in SKILL.md.

  1. Add a temporary console.log('[rx:build] ') inside the observable factory (the useMemo)
  2. Drive the studio with Playwright in headed Chrome and count the lines by tag. Snapshot the

What it can do on your machine

Read from SKILL.md and the folder at commit 73980e6. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • rg
    • pnpm
    • npm

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use pnpm and npm, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names these keys or tokens, usually read from environment variables:

    • STUDIO_AUTH_TOKEN

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

React Rx Hook Audit loads about 3k tokens when it runs. Until then it costs about 101 tokens; SKILL.md has 1,081 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~101
When it runs · the whole SKILL.md, loaded when a task matches
~3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from sanity-io/sanity at commit 73980e6, republished under its MIT licence (© sanity-io). 1,081 words, ~3,004 tokens.

Download SKILL.mdSave it as .claude/skills/react-rx-hook-audit/SKILL.md (or your agent's skills folder).
name
react-rx-hook-audit
description
Find react-rx hook call sites (useObservable, useSyncObservable, useObservablePromise) whose observable identity churns or that re-render more than needed, verify the suspicion at runtime, and refactor them to the useValuePreview pattern. Use when reviewing or writing a component or hook that calls these hooks, or when a re-render, loading flash or resubscribe storm is suspected.

react-rx hook audit

Start here

Use when a component or hook calls useObservable, useSyncObservable or useObservablePromise, or when you suspect a re-render, loading flash or resubscribe storm.

Read the reference refactor packages/sanity/src/core/preview/useValuePreview.ts and its test packages/sanity/src/core/preview/__test__/useValuePreview.test.tsx before you change a hook.

react-rx keeps one shared store per observable identity. A new identity is a new store and a new subscription of the source on commit, even when the pipeline is the same.

  • react-rx 7 (installed since #14643) has no warm-up. Every identity change renders initialValue once and resubscribes on commit, so identity churn shows up as loading flashes. initialValue is required and omitting it throws during render. useObservableSubject replaces useObservableEvent.
  • react-rx 6 subscribed a replacement observable once during render (needsWarmUp and warmUp in its dist/index.js, npm pack react-rx@6.0.1 to read them), so a synchronous emission showed in that render and the churn cost only the resubscribe. Code that looked fine on 6 flashes on 7.

Find candidates

bash
# run from the repo root; every call site (120 files at the time of writing)
rg -n "use(Sync)?Observable(Promise)?\(" packages/sanity/src packages/@sanity/vision/src -g '!**/*.test.*' -g '!**/__test*__/**'

# calls without an initialValue (28 hits; react-rx 7 throws on these)
rg -nU "use(Sync)?Observable\(\s*[^,()]+?\s*\)" packages/sanity/src packages/@sanity/vision/src -g '!**/*.test.*' -g '!**/__test*__/**'

# every useMemo in those files, reduced to its first line and its dependency array
rg -nU --multiline-dotall -o "useMemo(<[^>]*>)?\(\s*\(\)\s*=>.{0,900}?\n\s*\[[^\]\n]*\],?\s*\)" $(rg -l "use(Sync)?Observable(Promise)?\(" packages/sanity/src -g '!**/*.test.*' -g '!**/__test*__/**') | rg ":\d+:\s*(useMemo|\[)"

# files that call useObservablePromise and use(); confirm the two calls sit in different components
rg -l "useObservablePromise\(" packages/sanity/src packages/@sanity/vision/src -g '!**/*.test.*' | xargs rg -n "useObservablePromise\(|\buse\("

Read each dependency array from the third command. Flag a call site when:

  • A useMemo dependency that changes on edits: a document value, an array or object built during render, an inline [] or {} prop, or a recreated context value.
  • of(...) or a .pipe(...) is built inline in render or per memo run instead of hoisted.
  • The dependency list is a superset of what the pipeline reads.
  • useObservable or useSyncObservable is called without a stable initialValue.
  • use() reads a promise from useObservablePromise in the same component. See "react-rx: useObservablePromise and use() live in different components" in AGENTS.md.

Check these first (found with the commands above at this commit):

  • packages/sanity/src/core/hooks/useUserListWithPermissions.ts: state$ lists documentValue, the live document from CommentsProvider. Every edit rebuilds the grants observable.
  • packages/sanity/src/core/form/studio/assetSourceMediaLibrary/hooks/useEnsureMediaLibrary.ts: the memo lists props, and MediaLibraryProvider.tsx passes them as an inline object literal.
  • packages/sanity/src/core/canvas/actions/LinkToCanvas/useLinkToCanvas.ts: the memo lists document. An edit while LinkToCanvasDialog is open reruns the preflight request.
  • packages/sanity/src/core/releases/tool/components/releaseCTAButtons/ReleaseRevertButton/usePostPublishTransactions.ts: the memo lists documents, which updates live, so each update refetches the transaction log.

Count renders at runtime

Start the daemon and the studio per .agents/skills/react-devtools/SKILL.md and AGENTS.md. Then:

bash
pnpm --filter sanity-test-studio exec agent-react-devtools profile start
# drive the interaction, for example type ten characters into a field
pnpm --filter sanity-test-studio exec agent-react-devtools profile stop
pnpm --filter sanity-test-studio exec agent-react-devtools profile rerenders --limit 10
pnpm --filter sanity-test-studio exec agent-react-devtools profile report @cN
pnpm --filter sanity-test-studio exec agent-react-devtools get component @cN # hook slots

Limits: it counts renders, not subscriptions, so a resubscribe that renders the same value is invisible. Hidden <Activity> trees show as repeated first-mount fibers, not as re-renders.

Count subscriptions at runtime

  1. Add a temporary console.log('[rx:build] <hook>') inside the observable factory (the useMemo) and a console.log('[rx:subscribe] <hook>', <target id>) inside the switchMap project or the source factory. Remove both before you commit.
  2. Drive the studio with Playwright in headed Chrome and count the lines by tag. Snapshot the counters before and after the interaction. Run from the repo root with node:
js
import {chromium} from 'playwright'

const counts = {}
const executablePath = '/usr/local/bin/google-chrome'
const browser = await chromium.launch({executablePath, headless: false})
const page = await browser.newPage()
page.on('console', (message) => {
  const [tag] = message.text().split(' ', 1)
  if (tag.startsWith('[rx:')) counts[tag] = (counts[tag] ?? 0) + 1
})
const token = encodeURIComponent(process.env.STUDIO_AUTH_TOKEN) // never log it
// an existing document in the /test workspace, for example one you created through the mutate API
await page.goto(`http://localhost:3333/test/structure/author;${process.env.DOC_ID}#token=${token}`)
const input = page.getByTestId('field-name').getByTestId('string-input')
await input.waitFor()
const before = {...counts}
await input.pressSequentially('ten chars!')
await page.waitForTimeout(3000)
console.log({before, after: counts})
await browser.close()

Pitfalls seen in this repo:

  • sanity dev can serve a stale revision after two edits of one file within seconds. Confirm an hmr update line for your last edit in its terminal, or restart the server.
  • Keep the studio in bundledDev (the default) but run the server with the PID watchdog from the AGENTS.md gotchas. On vite 8.3 (PR #14700) one audit session pushed the server past 7 GB RSS.

Pass condition: during edits, [rx:build] is 0 for every host whose identity inputs did not change, and [rx:subscribe] equals the number of distinct input changes per host.

Show full SKILL.md (601 more words)Show less

Refactor

Reproduce the useValuePreview shape:

  1. Name the identity inputs: the inputs whose change must render initialValue again. In useValuePreview these are enabled, schemaType and the previewed document id. Everything else is a streamed input.

  2. Put the streamed inputs in one typed record (PreviewInputs) and useMemo it on its fields. Resolve overrides first, so the record carries the effective perspective and variant rather than both the caller's and the context's; a context change the caller overrides then never reaches the stream. One record, not one subject per input: two fields that change in the same render arrive together, so switchMap never subscribes an intermediate source.

  3. Hold the record in a BehaviorSubject fed from a useEffect. Replace the subject whenever any identity input changes, enabled included, seeded with the current render's inputs, with the "adjust state during render" pattern. A replacement observable must never read the inputs of an earlier render, and react-rx 6 subscribed it during render. This is useInputsSubject in useValuePreview.ts:

    ts
    function useInputsSubject(
      enabled: boolean,
      schemaType: SchemaType | undefined,
      inputs: PreviewInputs,
    ): BehaviorSubject<PreviewInputs> {
      const documentKey = getPreviewDocumentKey(inputs.value)
      const [current, setCurrent] = useState(() => ({
        enabled,
        schemaType,
        documentKey,
        inputs$: new BehaviorSubject(inputs),
      }))
    
      let {inputs$} = current
      if (
        current.enabled !== enabled ||
        current.schemaType !== schemaType ||
        current.documentKey !== documentKey
      ) {
        inputs$ = new BehaviorSubject(inputs)
        setCurrent({enabled, schemaType, documentKey, inputs$})
      }
    
      useEffect(() => {
        inputs$.next(inputs)
      }, [inputs$, inputs])
    
      return inputs$
    }
  4. Build the observable in a useMemo whose dependencies are the identity inputs, the subject and the store function only. Pipe inputs$ through distinctUntilChanged(dequal), switchMap into the source, then distinctUntilChanged with an output comparator (isSameState in useValuePreview.ts) that compares the value with react-fast-compare and errors by identity.

  5. Hoist constant observables to module scope, as in IDLE_STATE_OBSERVABLE = of(IDLE_STATE), so returning one from the memo keeps a single identity and store.

  6. Keep useSyncObservable(observable, INITIAL_STATE) when consumers read the first frame synchronously. Use useObservable otherwise.

Cost the pattern accepts: a change that alters the output takes one extra render (render with the previous snapshot, the effect pushes, the store notifies, render again). A change that leaves the output equal costs no extra render.

Do not apply the pattern when the observable has no value-shaped inputs (ids, strings and stores only) or when consumers need the render-time synchronous update on every change. Do not reach for the deprecated useUnique to stabilize an input.

Test

Copy the harness pattern from useValuePreview.test.tsx and assert on literal frames and counts:

  • A Harness component pushes every rendered frame ({isLoading, title, error}) into an array.
  • The mocked source is an Observable that counts subscriptions.active and subscriptions.total in its subscribe function and teardown.
  • flush() awaits one macrotask inside act, so react-rx's share({resetOnRefCountZero: () => timer(0, asapScheduler)}) releases the old source before you assert counts.

Write these three tests. They catch the regressions the refactor guards against:

  1. Same target, edited twice: frames.slice(settled).filter((frame) => frame.isLoading) is [] and, after flush(), subscriptions is {active: 1, total: 3}.
  2. Equal inputs rebuilt every render (a new [] prop or an equal object): {active: 1, total: 1}.
  3. Identity change (another document or schema type): every frame since the switch is the loading frame, the previous target's title never renders, then the new title renders.

At this commit useValuePreview.test.tsx (23 tests) passes on the installed react-rx 7.0.0, and main's previous hook fails 7 of them there: loading frames on same-document edits and perspective changes, a second render for an edit that leaves the preview unchanged, three previews for equal inline inputs, a resubscribe on an overridden context change, and StrictMode. To see which of those the react-rx 6 warm-up masked, run the file against the 6.0.1 dist. The installed dist files are hard links into the pnpm store, so never write into them in place; unlink first:

bash
RX=packages/sanity/node_modules/react-rx/dist
cp -a $RX /tmp/react-rx7-dist
(cd /tmp && npm pack react-rx@6.0.1 --silent && tar xzf react-rx-6.0.1.tgz)
rm $RX/index.js $RX/index.d.ts && cp /tmp/package/dist/index.js /tmp/package/dist/index.d.ts $RX/
pnpm vitest run --project=sanity <the test file>
rm $RX/index.js $RX/index.d.ts && cp /tmp/react-rx7-dist/index.js /tmp/react-rx7-dist/index.d.ts $RX/

© sanity-io, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/react-rx-hook-audit of sanity-io/sanity.

Open the folder on GitHubat commit 73980e6

Compare with similar skills

React Rx Hook Audit next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

React Rx Hook Audit compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
React Rx Hook Audit this skillsanity-io/sanity6.4k—~3kAutomated safety check: PassMIT
Nuqstrycompai/crm11k1 repos~1.7kAutomated safety check: PassMIT
Refactor React Effectslangfuse/langfuse36k—~1.7kAutomated safety check: PassCustom licence
No Use Effectmattiacerutti/supernova1862 repos~1.7kAutomated safety check: PassMIT
React Best Practicesshapeshift/web2061 repos~2kAutomated safety check: PassMIT
Nextjs App Architecturejakubwarkusz/themes1231 repos~2.5kAutomated safety check: PassMIT

Similar skills

  • Nuqs

    trycompai/crm

    nuqs (type-safe URL query state) best practices for Next.js and other React frameworks.

    11k GitHub starsUsed in 1 repo~1.7k tokens
    DevelopmentAuto-check passed
  • Refactor React Effects

    langfuse/langfuse

    Refactor avoidable React useEffect usage in Langfuse frontend code.

    36k GitHub stars~1.7k tokensUpdated today
    DevelopmentAuto-check passed
  • No Use Effect

    mattiacerutti/supernova

    Enforce the no-useEffect rule when writing or reviewing React code.

    186 GitHub starsUsed in 2 repos~1.7k tokens
    DevelopmentAuto-check passed
  • React Best Practices

    shapeshift/web

    Comprehensive React and Next.js performance optimization guide with 40+ rules for eliminating waterfalls, optimizing bundles, and improving rendering.

    206 GitHub starsUsed in 1 repo~2k tokens
    DevelopmentAuto-check passed
  • Nextjs App Architecture

    jakubwarkusz/themes

    Build or audit Next.js 16 App Router apps using a next-beats-style React Server Components architecture.

    123 GitHub starsUsed in 1 repo~2.5k tokens
    DevelopmentAuto-check passed
  • Migrate Component

    asyncapi/generator

    Promote a duplicated React/JSX template-local component into the shared @asyncapi/generator-components package.

    1.1k GitHub stars~3k tokensUpdated 4 days ago
    DevelopmentAuto-check passed

More from sanity-io/sanity

All 34 skills in this repo
  • Playwright CLI

    sanity-io/sanity

    Official

    Automates browser interactions for web testing, form filling, screenshots, and data extraction.

    6.4k GitHub starsUsed in 18 repos~1.9k tokens
    Auto-check passed
  • Find Skills

    sanity-io/sanity

    Official

    Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities.

    6.4k GitHub starsUsed in 67 repos~1.2k tokens
    Auto-check passed
  • Official

    React and Next.js performance optimization guidelines from Vercel Engineering.

    6.4k GitHub starsUsed in 129 repos~1.6k tokens
    Auto-check passed
  • Before And After

    sanity-io/sanity

    Official

    Add existing screenshots or screen recordings to a GitHub pull request as a before/after or preview block.

    6.4k GitHub starsUsed in 1 repo~2.1k tokens
    Auto-check passed
  • React Devtools

    sanity-io/sanity

    Official

    React DevTools CLI for AI agents. An agent skill from sanity-io/sanity.

    6.4k GitHub starsUsed in 3 repos~2.1k tokens
    Auto-check passed
  • TDD

    sanity-io/sanity

    Official

    Test-driven development with red-green-refactor loop. An agent skill from sanity-io/sanity.

    6.4k GitHub starsUsed in 20 repos~1k tokens
    Auto-check passed

Works with

Categories

Questions about React Rx Hook Audit

What does React Rx Hook Audit do?

Find react-rx hook call sites (useObservable, useSyncObservable, useObservablePromise) whose observable identity churns or that re-render more than needed, verify the suspicion at runtime, and…. React Rx Hook Audit is an agent skill from sanity-io/sanity, published by the product's own GitHub organization. Find react-rx hook call sites (useObservable, useSyncObservable, useObservablePromise) whose observable identity churns or that re-render more than needed, verify the suspicion at runtime, and refactor them to the useValuePreview pattern.

When should I use React Rx Hook Audit?

React Rx Hook Audit fits situations like: writing a component; hook that calls these hooks; resubscribe storm is suspected.

How do I install React Rx Hook Audit in Claude Code?

Run `npx skills add sanity-io/sanity --skill react-rx-hook-audit -a claude-code`. Or copy the skill folder (.agents/skills/react-rx-hook-audit in sanity-io/sanity) into .claude/skills/react-rx-hook-audit in your project. Claude Code loads it when a task matches its description.

How do I install React Rx Hook Audit in Codex?

Run `npx skills add sanity-io/sanity --skill react-rx-hook-audit -a codex`. Or copy the skill folder (.agents/skills/react-rx-hook-audit in sanity-io/sanity) into .agents/skills/react-rx-hook-audit in your project. Codex loads it when a task matches its description.

Can I use React Rx Hook Audit in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add sanity-io/sanity --skill react-rx-hook-audit -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/react-rx-hook-audit, .gemini/skills/react-rx-hook-audit, .github/skills/react-rx-hook-audit and .opencode/skills/react-rx-hook-audit in your project.

What does React Rx Hook Audit need to run?

Going by SKILL.md and its folder, React Rx Hook Audit needs the command-line tools its instructions call (rg, pnpm and npm) and credentials named STUDIO_AUTH_TOKEN. Our summary lists: A credential in STUDIO_AUTH_TOKEN.

Does React Rx Hook Audit access the network?

SKILL.md contains no URLs. Its commands use npm, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is React Rx Hook Audit safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does React Rx Hook Audit use?

React Rx Hook Audit is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does React Rx Hook Audit use?

About 3k tokens (SKILL.md is roughly 12k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to React Rx Hook Audit?

Skills that share tags, products or a category with React Rx Hook Audit: Nuqs (trycompai/crm, 11k stars), Refactor React Effects (langfuse/langfuse, 36k stars), No Use Effect (mattiacerutti/supernova, 186 stars) and React Best Practices (shapeshift/web, 206 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains React Rx Hook Audit?

sanity-io (a GitHub organization, an official publisher) maintains it in sanity-io/sanity, which has 6,352 GitHub stars. The repository holds 34 skills in this directory. The repository was last updated on October 8, 2026.

Source: sanity-io/sanity on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.