次のような場合に使用: ユーザーインターフェース(ユーザーが画面で見る操作部分)を含む値を構築する場合。ダッシュボード、ウェブアプリ、ランディングページ、フォーム、管理ツール、ブラウザに表示される任意のものが対象となります。 カバーする内容: - JSX/React の記述方法 - Twind/Tailwind のスタイリング手法 - React のバージョン固定方法 - ソースコード表示リンクの必須要件 - 避けるべき手法(テンプレート文字列による HTML 記述や外部リソースの読み込みなど)
Use when building any val with a user interface — dashboards, web apps, landing pages, forms, admin tools, anything users see in a browser. Covers JSX/React conventions, Twind/Tailwind styling, React version pinning, the view-source link requirement, and what to avoid (template-string HTML, external assets).
UIを表示する値については、特に指示がなければ React コンポーネントを .tsx ファイルで構築してください。templates/react-hono-starter テンプレートはこれに対応しているため、最初から構築するのではなく remix_val でここから始めることをお勧めします。
マークアップ、スタイル、スクリプトは実ファイルに記述し、テンプレート文字列(例:new Response(\<html>...</html>`)`)は避けてください。テンプレート文字列内のコードはシンタックスハイライト(構文の色分け)、リント(文法チェック)、型チェック、レビューに対応していません。
.tsx — React/JSX コンポーネント、ロジックやインタラクティブ機能を含む UI.html — 静的なマークアップのみ.ts — サーバーコードとスクリプトUIは .tsx ファイルでコンポーネント単位で構築してください。1つの大きなページを描画するのではなく、小さなコンポーネントを組み合わせます。
実行時に Tailwind ユーティリティクラスを適用できる Twind(ビルドステップが不要)を優先してください。HTML の基本テンプレートにスクリプトを追加します:
<script src="https://cdn.twind.style" crossorigin></script>
その後、JSX 内で Tailwind クラスを直接使用します:
<div className="flex items-center gap-4 p-6 rounded-lg bg-white shadow">
<h1 className="text-2xl font-bold">Hello</h1>
</div>
ユーザーが別の方法を指示しない限り、インラインの <style> タグ、CSS-in-JS オブジェクト、別の .css ファイルは避けてください。
std/utils の serveImmutableFile を使ってクライアント用のモジュールを配信してください。ブラウザはこれらを永続的にキャッシュし、値を公開するときにバージョンがアップデートされると自動的に無効化されます(詳しくは client-side-js スキルのパターンを参照)。キャッシュされない frontend/root.tsx シェル(hono/jsx)は immutableFileUrl でエントリーポイントとファビコンをスタンプします:
// frontend/root.tsx — Root() HTML シェル内:
<script src={immutableFileUrl("/frontend/index.tsx")} type="module" />
// index.ts:
app.get("/", (c) => c.html(Root()));
app.get("/__immutable/*", (c) => serveImmutableFile(c.req.path));
すべての UI 値は、ユーザーがそのソースコードを確認したり、改造版を作成(remix)したりできるようにする必要があります。以下の 2 つの部分が必須です:
import { parseVal } from "https://esm.town/v/std/utils/index.ts";
app.get("/source", (c) => c.redirect(parseVal().links.self.val));
<a href="/source">view source</a>
よくあるエラー「Cannot read properties of null (reading 'useState')」は、React の依存パッケージが異なるバージョンを読み込んでいることを意味します。React 関連のインポートはすべてバージョン 18.2.0 に固定してください:
import SomeLib from "https://esm.sh/some-lib?deps=react@18.2.0,react-dom@18.2.0";
破損する可能性がある外部画像やホストされたアセットは使用しないでください。以下を優先してください:
ブラウザのエラーを値のログに送信する(get_logs で表示可能)には、HTML シェルに以下のスクリプトを含めてください:
<script src="https://esm.town/v/std/catch"></script>
UI 値を編集したら、fetch_val_endpoint を実行してページがエラーなく描画されることを確認し、その後 get_logs でクライアント側のエラーがないかチェックしてください。この両方を確認してから、変更が完了したと報告してください。
For any val that renders a UI, prefer to build it with React components in .tsx files, unless the user states otherwise. The templates/react-hono-starter template is set up for this — start there with remix_val instead of building from scratch.
Put markup, styles, and scripts in real files — avoid template literal strings (e.g. new Response(\<html>...</html>`)`). Code in template strings has no syntax highlighting, no linting, no type checking, and is unreviewable.
.tsx — React/JSX components, any UI with logic or interactivity.html — purely static markup.ts — server code and scriptsBuild UI component by component in .tsx files. Compose small components rather than rendering one giant page.
Prefer Twind to apply Tailwind utility classes at runtime — no build step required. Add the script to your HTML shell:
<script src="https://cdn.twind.style" crossorigin></script>
Then use Tailwind classes directly in JSX:
<div className="flex items-center gap-4 p-6 rounded-lg bg-white shadow">
<h1 className="text-2xl font-bold">Hello</h1>
</div>
Avoid inline <style> tags, CSS-in-JS objects, or separate .css files, unless the user says otherwise.
Serve client modules with serveImmutableFile from std/utils — browsers cache
them immutably, and publishing bumps the val's version, which invalidates
automatically (full pattern: the client-side-js skill). A never-cached
frontend/root.tsx shell (hono/jsx) stamps the entry and favicon with
immutableFileUrl:
// frontend/root.tsx — in the Root() HTML shell:
<script src={immutableFileUrl("/frontend/index.tsx")} type="module" />
// index.ts:
app.get("/", (c) => c.html(Root()));
app.get("/__immutable/*", (c) => serveImmutableFile(c.req.path));
Every UI val should expose a way for users to see and remix its source. Both parts are required:
import { parseVal } from "https://esm.town/v/std/utils/index.ts";
app.get("/source", (c) => c.redirect(parseVal().links.self.val));
<a href="/source">view source</a>
A common error — "Cannot read properties of null (reading 'useState')" — means a React sub-dependency is loading a different React version. Pin all React-related imports to 18.2.0:
import SomeLib from "https://esm.sh/some-lib?deps=react@18.2.0,react-dom@18.2.0";
Do not use external images or hosted assets that may break. Prefer:
To send browser errors back to val logs (visible via get_logs), include this script in your HTML shell:
<script src="https://esm.town/v/std/catch"></script>
After editing a UI val, call fetch_val_endpoint to confirm the page renders without error, then check get_logs for any client-side errors. Don't report the change as done without both.
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。