React Ui

作者 val-town2d3ec654b6a7无许可证收录于 2026年10月8日更新于 2026年10月8日

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).

AI 生成的概览

指导使用 React/JSX 组件、Twind/Tailwind 样式、版本锁定和源码链接来构建浏览器界面。

功能
提供以 .tsx 文件中的 React 组件构建面向用户界面的约定,涵盖文件组织、Twind/Tailwind 工具类样式、不可变资源服务和必需的查看源码链接。还涉及将 React 导入锁定到 18.2.0、避免外部资源以及上报客户端错误。该技能仅为说明性内容,本身不生成文件。
适用场景
适用于构建用户在浏览器中看到的任何界面,例如仪表盘、Web 应用、落地页、表单或管理工具。它面向基于 React 的前端工作,而非仅服务端代码。
运行要求
该技能不附带脚本。它假定具备 React/JSX 工具链、通过 CDN 引入的 Twind,以及所引用的 val 平台工具和端点,用于提供资源、获取端点和读取日志。

React UI

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.

File conventions

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 scripts

Build UI component by component in .tsx files. Compose small components rather than rendering one giant page.

Styling: Twind + Tailwind

Prefer Twind to apply Tailwind utility classes at runtime — no build step required. Add the script to your HTML shell:

html
<script src="https://cdn.twind.style" crossorigin></script>

Then use Tailwind classes directly in JSX:

tsx
<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.

Serving assets: versioned + immutable

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:

tsx
// 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));

View source link

Every UI val should expose a way for users to see and remix its source. Both parts are required:

  1. Backend route:
    ts
    import { parseVal } from "https://esm.town/v/std/utils/index.ts";app.get("/source", (c) => c.redirect(parseVal().links.self.val));
  2. Visible link in the frontend:
    tsx
    <a href="/source">view source</a>

React version pinning

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:

ts
import SomeLib from "https://esm.sh/[email protected],[email protected]";

Assets

Do not use external images or hosted assets that may break. Prefer:

  • Emojis or unicode symbols
  • Inline SVG
  • Icon fonts via CDN (Lucide, Font Awesome)

Surfacing client-side errors

To send browser errors back to val logs (visible via get_logs), include this script in your HTML shell:

html
<script src="https://esm.town/v/std/catch"></script>

Verifying changes

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.

来源与署名

来源:val-town/plugins位于plugin/skills/react-ui提交2d3ec65

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架