rab-react

A guide to using the @rabjs/react library for React applications with observable state. It explains components that update when state changes, service classes, dependency injection, asynchronous state, and events.

In plain words
What is it for?
Use it when writing or changing code that uses @rabjs/react, including observable components, RSRoot, RSStrict, services, and injected business logic.
Why use it?
It helps the agent follow the library's required patterns, such as wrapping components with observer or view so state changes update the screen.

Skill for Claude CodeCodex

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.

agentmods
npx agentmods add skills/ximing/rab/rab-react
Any agent
npx skills add ximing/rab --skill rab-react
Clone the repo
git clone --depth 1 https://github.com/ximing/rab

Made for: Claude Code, Codex.

Per session 149 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,114 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00149 $0.05114
Opus 5 $0.00075 $0.02557
Sonnet 5 $0.00030 $0.01023
Haiku 4.5 $0.00015 $0.00511

Measured yesterday against content hash 101ebfcf026b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

rab-react 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 yesterday.

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.

skills/rab-react/SKILL.md · 681 lines

How it starts

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

@rabjs/react 快速参考

这是为大模型优化的 @rabjs/react (RSJS) 快速参考指南,聚焦最核心的使用模式。

🎯 五大核心概念

1. 响应式组件:observerview

基本规则:组件必须使用 observerview 包裹才能自动响应状态变化。

import { observer, view } from "@rabjs/react";

// ✅ 方式 1:observer(推荐用于函数组件)
const Counter = observer(() => {
  const service = useService(CounterService);
  return <div>{service.count}</div>; // 自动追踪 count 变化
});

// ✅ 方式 2:view(支持类组件和函数组件)
class Counter extends React.Component {
  render() {
    const { store } = this.props;
    return <div>{store.count}</div>;
  }
}
export default view(Counter);

// ❌ 错误:忘记使用 observer
const Counter = () => {
  const service = useService(CounterService);
  return <div>{service.count}</div>; // 不会自动更新!
};

关键点

  • 必须在 observer 内部访问 observable 属性
  • 不要解构 observable 对象(会破坏响应性)
  • viewobserver 功能相同,view 额外支持类组件

2. Service:业务逻辑容器

基本规则:所有业务逻辑都应该封装在 Service 类中,包括组件内的操作方法。

import { Service } from "@rabjs/react";

export class CounterService extends Service {
  // 属性自动是 observable
  count = 0;

  // 方法自动是 action(批量更新)
  increment() {
    this.count++;
  }

  decrement() {
    this.count--;
  }

  // 计算属性(getter)
  get doubleCount() {
    return this.count * 2;
  }

  // 异步方法自动追踪 loading 和 error
  async fetchData() {
    const response = await fetch("/api/data");
    this.count = await response.json();
  }
}

// 在组件中访问异步状态
const Component = observer(() => {
  const service = useService(CounterService);

  // 自动生成的状态
  if (service.$model.fetchData.loading) return <div>加载中...</div>;
  if (service.$model.fetchData.error) return <div>错误</div>;
  // 可以直接使用,框架会处理好 this指向问题
  return <div onClick={service.fetchData}>{service.count}</div>;
});

关键点

  • Service 类继承自 Service 基类
  • 所有属性自动是响应式的(observable)
  • 所有方法默认就是 action(批量更新),不需要也不应该再写 @Action 装饰器
  • 只有需要关闭批量更新时才用 @SyncAction 标记方法
  • 异步方法自动追踪 loadingerror 状态(通过 $model.methodName

3. useService + bindServices:连接组件和 Service

基本规则:使用 bindServices 注册 Service,使用 useService 获取 Service 实例。

Read the full file on GitHub · 681 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. yesterday First seen · 681 lines · 149 tokens per session scan A 101ebfcf026b

Subscribe to this mod's changes

rab-react is a skill published in the GitHub repository ximing/rab (12 stars, last pushed yesterday), licensed MIT. It adds 149 tokens to every session and 5,114 once invoked, about $0.0007 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-08-30.

Related

Other skills, from other repositories

menu-interactions

Wire mouse, wheel and touch input for react-horizontal-scrolling-menu: onWheel/onScroll are plain (api, event) => void callbacks, while ALL mouse/touch props (onMouseDown, onMouseUp, onMouseMove, onMouseLeave, onTouchStart, onTouchMove, onTouchEnd) are handler factories (api) => (event) => void. Covers mouse…

asmyshlyaev177/react-horizontal-scrolling-menu · 147 tokens

menu-migration

Detect and upgrade pre-v8 react-horizontal-scrolling-menu patterns that agents trained on older data still generate: destructured visibleElements/isFirstItemVisible/isLastItemVisible/initComplete (removed v6), Separator items, separatorClassName and getPrevItem/getNextItem (removed v7), the Arrows prop (removed v3)…

asmyshlyaev177/react-horizontal-scrolling-menu · 160 tokens

menu-recipes

Recipes composed on the react-horizontal-scrolling-menu public API — NOT props: autoplay (setInterval + scrollNext gated on menuVisible), infinite loop/carousel (clone head/tail + scrollLeft teleport at seams), center on click (scrollToItem 'center'), save/restore scroll position (onUpdate, onInit, scrollContainer)…

asmyshlyaev177/react-horizontal-scrolling-menu · 145 tokens

menu-setup

Build a working react-horizontal-scrolling-menu: install, the mandatory 'react-horizontal-scrolling-menu/dist/styles.css' import, ScrollMenu with a unique itemId per child, arrow components via VisibilityContext with useLeftArrowVisible/useRightArrowVisible, Header/Footer slots, and CSS customization (fixed item…

asmyshlyaev177/react-horizontal-scrolling-menu · 115 tokens

menu-testing-ssr

Server rendering and testing for react-horizontal-scrolling-menu: the library is client-only ('use client' required in React Server Components, else "createContext is not a function"), SSR first paint is controlled by the useIsVisible defaultValue argument (canonical ('first', true) / ('last', false))…

asmyshlyaev177/react-horizontal-scrolling-menu · 144 tokens

menu-transitions-rtl

Animate react-horizontal-scrolling-menu scrolling and build right-to-left menus: noPolyfill defaults to true since v8, so transitionDuration (default 500), a custom-easing-function transitionBehavior, and per-call ScrollOptions { duration, boundary } on scrollToItem/scrollNext/scrollPrev are silently ignored unless…

asmyshlyaev177/react-horizontal-scrolling-menu · 137 tokens