react-use-ref

react-use-ref is a skill for Claude Code from ncaq/konoka. It costs 34 tokens per session (1,365 once invoked), scanned A, original, Apache-2.0.

A React coding guide for avoiding unnecessary useRef, a React feature for holding mutable values or referring to page elements. It recommends HTML features, state, libraries, or custom hooks when they fit better.

In plain words
What is it for?
Use it when writing or reviewing React components, especially controls such as details sections and popovers that can use standard HTML features.
Why use it?
It helps avoid code whose changes are not reflected in the screen, duplicates React's state management, or is harder to test and reuse.

Skill for Claude Code

Written for Claude Code: user-invocable in frontmatter.

Part of the web-tasuke plugin — 17 skills shipped together

Good fit Use it when writing or reviewing React components, especially controls such as details sections and popovers that can use standard HTML features.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/ncaq/konoka/react-use-ref
View source ↗ ncaq/konoka
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.

Any agent
npx skills add ncaq/konoka --skill react-use-ref
Clone the repo
git clone --depth 1 https://github.com/ncaq/konoka

Made for: Claude Code.

Or install web-tasuke, the plugin that ships this one along with the rest of its 17 skills.

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 react-use-ref

README.md
[![agentmods](https://agentmods.dev/badge/skills/ncaq/konoka/react-use-ref/github.svg)](https://agentmods.dev/skills/ncaq/konoka/react-use-ref)
Your own site
<a href="https://agentmods.dev/skills/ncaq/konoka/react-use-ref"><img src="https://agentmods.dev/badge/skills/ncaq/konoka/react-use-ref/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 react-use-ref

Your own site · 80×15
<a href="https://agentmods.dev/skills/ncaq/konoka/react-use-ref"><img src="https://agentmods.dev/badge/skills/ncaq/konoka/react-use-ref.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 34 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,365 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.00034 $0.01365
Opus 5 $0.00017 $0.00682
Sonnet 5 $0.00007 $0.00273
Haiku 4.5 $0.00003 $0.00136

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

Security

Grade A, and why

react-use-ref 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 4d 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.

plugins/web-tasuke/skills/react-use-ref/SKILL.md · 155 lines

How it starts

The opening of the file, as written. The whole thing — 155 lines — stays where its author put it; the contents beside it link to each section on GitHub.

useRefの使用を避ける

useRefは命令的なコードになりやすく、 Reactの宣言的なモデルと相性がよくありません。 使う前に代替手段がないか検討してください。

なぜuseRefを避けたいのか

  • ref.currentはミュータブルであり、レンダリングサイクルと同期しません。値の変更がUIに反映されず、予期しない挙動を起こしやすいです
  • 命令的なDOM操作はReactの状態管理と二重管理になりやすいです
  • テストが難しくなります。DOMの状態をテストするにはDOMのセットアップが必要になります
  • コンポーネントの再利用性が下がります。DOM構造に依存したロジックは別の場所で使い回しにくいです
  • ref.currentへの代入は「いつ読んでも最新」という暗黙の前提に依存しており、データフローが追いにくくなります

代替手段の検討

HTML標準の機能を使う

ブラウザが提供する宣言的なHTML要素や属性で解決できないか、 まず検討してください。

// Bad: useRefで開閉を命令的に管理
const detailsRef = useRef<HTMLDetailsElement>(null);
const toggle = () => {
  if (detailsRef.current) {
    detailsRef.current.open = !detailsRef.current.open;
  }
};

// Good: HTML標準の<details>要素なら宣言的に開閉できる
<details>
  <summary>詳細を表示</summary>
  <p>ここに詳細が表示されます。</p>
</details>;
// Bad: useRefでポップオーバーの表示を命令的に管理
const popoverRef = useRef<HTMLDivElement>(null);
const showPopover = () => popoverRef.current?.showPopover();

// Good: popover属性とpopoverTargetで宣言的に表現
<button popoverTarget="my-popover">開く</button>
<div id="my-popover" popover="auto">ポップオーバーの内容</div>

<details><dialog>popover属性、<input type="date">など、 以前はJavaScriptが必要だった機能の多くが現在はHTML標準で提供されています。

宣言的なライブラリを使う

DOM操作を抽象化してくれるライブラリがあれば、 そちらを優先してください。

// Bad: useRefとuseEffectでIntersectionObserverを管理
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
  const observer = new IntersectionObserver(([entry]) => {
    setIsVisible(entry.isIntersecting);
  });
  if (ref.current) observer.observe(ref.current);
  return () => observer.disconnect();
}, []);

// Good: ライブラリに任せる(react-intersection-observerの例)
const { ref, inView } = useInView();

stateで管理する

レンダリングに反映すべき値をuseRefで持っているなら、 それはuseStateで管理すべきです。

// Bad: useRefで値を保持してレンダリングと同期しない
const countRef = useRef(0);
countRef.current += 1;

// Good: stateで管理してUIに反映する
const [count, setCount] = useState(0);

クロージャやローカル変数で済ませる

useEffect内だけで使う値は、 useEffectのクロージャ内で管理すれば十分です。

// Bad: タイマーIDをuseRefで保持
const timerIdRef = useRef<number>();
useEffect(() => {
  timerIdRef.current = window.setInterval(() => {
    /* ... */
  }, 1000);
  return () => clearInterval(timerIdRef.current);
}, []);

// Good: useEffect内のローカル変数で完結
useEffect(() => {
  const timerId = window.setInterval(() => {
    /* ... */
  }, 1000);
  return () => clearInterval(timerId);
}, []);

Read the full file on GitHub · 155 lines

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. 4d ago First seen · 155 lines · 34 tokens per session scan A 6a11fd70e464

Subscribe to this mod's changes

react-use-ref is a skill published in the GitHub repository ncaq/konoka (3 stars, last pushed yesterday), licensed Apache-2.0. It adds 34 tokens to every session and 1,365 once invoked, about $0.0002 per session on Opus 5. 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-05.

Related

Other skills, from other repositories