11# @fictjs/react
22
3- Fict 与 React 的互操作层,采用可控的 React Islands 模型。
3+ A React interoperability layer for Fict, based on a controlled React Islands model.
44
5- ## 功能
5+ ## Features
66
7- - ` reactify ` :把 React 组件包装成 Fict 组件( CSR + SSR)。
8- - ` ReactIsland ` :声明式岛屿组件,支持 ` props ` getter。
9- - ` reactify$ ` : QRL 可序列化 React 岛屿,支持延迟加载。
10- - ` installReactIslands ` :客户端扫描并挂载 ` data-fict-react ` 岛屿。
11- - ` reactAction$ ` :把 Fict QRL action 作为可序列化 React callback 传递。
12- - ` fictReactPreset ` :Vite 下按目录隔离 React JSX 转换(默认 ` src/react/** ` )。
7+ - ` reactify ` : Wrap a React component as a Fict component ( CSR + SSR).
8+ - ` ReactIsland ` : Declarative island component with ` props ` getter support.
9+ - ` reactify$ ` : QRL-serializable React island with lazy loading support.
10+ - ` installReactIslands ` : Scan and mount ` data-fict-react ` islands on the client.
11+ - ` reactAction$ ` : Pass Fict QRL actions as serializable React callbacks.
12+ - ` fictReactPreset ` : Isolate React JSX transform by directory in Vite (default ` src/react/** ` ).
1313
14- ## 安装
14+ ## Install
1515
1616``` bash
1717pnpm add @fictjs/react react react-dom @fictjs/runtime
1818```
1919
20- ## 用法
20+ ## Usage
2121
22- ### 1) ` reactify ` ( Eager)
22+ ### 1) ` reactify ` ( Eager)
2323
2424``` ts
2525import { reactify } from ' @fictjs/react'
@@ -31,7 +31,7 @@ function ReactButton(props: { text: string }) {
3131
3232const FictButton = reactify (ReactButton )
3333
34- // Fict 里使用
34+ // Use in Fict
3535;< FictButton text = {prop(() => state .text )} / >
3636```
3737
@@ -48,7 +48,7 @@ import { ReactIsland } from '@fictjs/react'
4848/ >
4949```
5050
51- ### 3) ` reactify$ ` ( Resumable)
51+ ### 3) ` reactify$ ` ( Resumable)
5252
5353``` ts
5454import { reactify$ } from ' @fictjs/react'
@@ -61,24 +61,25 @@ export const FictButton$ = reactify$({
6161})
6262```
6363
64- > ` reactify$ ` 会输出 ` data-fict-react ` + ` data-fict-react-props ` ,可在客户端按策略加载。
64+ > ` reactify$ ` outputs ` data-fict-react ` + ` data-fict-react-props ` , which can be mounted on the client by strategy.
6565
66- ### 4) 客户端 loader
66+ ### 4) Client Loader
6767
6868``` ts
6969import { installReactIslands } from ' @fictjs/react'
7070
7171installReactIslands ()
7272```
7373
74- ` installReactIslands ` 的 host 属性约束:
74+ ` installReactIslands ` host attribute constraints:
7575
76- - 可动态更新并触发刷新:` data-fict-react-props ` 、` data-fict-react-action-props `
77- - 初始化后不可变(变更需重建 island host):` data-fict-react-client ` 、` data-fict-react-ssr ` 、` data-fict-react-prefix `
78- - 可变且会触发重建:` data-fict-react ` (QRL 变化会 dispose + remount)
79- - 对不可变属性的运行时变更:开发环境会告警,生产环境静默忽略
76+ - Dynamically updatable (triggers refresh): ` data-fict-react-props ` , ` data-fict-react-action-props `
77+ - Immutable after initialization (recreate the island host to apply changes):
78+ ` data-fict-react-client ` , ` data-fict-react-ssr ` , ` data-fict-react-prefix `
79+ - Mutable and triggers runtime rebuild: ` data-fict-react ` (QRL changes cause dispose + remount)
80+ - Runtime mutations of immutable attributes: warning in development, silent ignore in production
8081
81- ### 5) 可序列化回调( Action)
82+ ### 5) Serializable Callback ( Action)
8283
8384``` ts
8485import { reactAction$ } from ' @fictjs/react'
@@ -88,8 +89,8 @@ import { reactAction$ } from '@fictjs/react'
8889/ >
8990```
9091
91- 默认会把回调类 props( ` /^on[A-Z]/ ` )中的 action ref materialize 成可调用函数。
92- 如果你的回调 prop 不是 ` onX ` 命名,需要通过 ` actionProps ` 显式声明:
92+ By default, action refs in callback-like props ( ` /^on[A-Z]/ ` ) are materialized into callable functions.
93+ If your callback prop is not named like ` onX ` , declare it explicitly via ` actionProps ` :
9394
9495``` ts
9596const RemoteReactIsland = reactify$ ({
@@ -99,7 +100,7 @@ const RemoteReactIsland = reactify$({
99100})
100101```
101102
102- 对应 loader 场景可通过 host 属性传入:
103+ For loader-based usage, pass this through host attributes:
103104
104105``` html
105106<div
@@ -108,7 +109,7 @@ const RemoteReactIsland = reactify$({
108109></div >
109110```
110111
111- ### 6) Vite preset( React lane)
112+ ### 6) Vite Preset ( React Lane)
112113
113114``` ts
114115import { defineConfig } from ' vite'
@@ -123,14 +124,14 @@ export default defineConfig({
123124})
124125```
125126
126- ## 客户端策略
127+ ## Client Strategies
127128
128- - ` load ` :尽快挂载。
129- - ` idle ` :空闲时挂载( ` requestIdleCallback ` 优先)。
130- - ` visible ` :进入视口时挂载( ` IntersectionObserver ` )。
131- - ` only ` :仅客户端渲染(不走 SSR hydrate)。
129+ - ` load ` : Mount as soon as possible.
130+ - ` idle ` : Mount when idle ( ` requestIdleCallback ` preferred).
131+ - ` visible ` : Mount when entering the viewport ( ` IntersectionObserver ` ).
132+ - ` only ` : Client-only rendering (no SSR hydrate).
132133
133134## Internal Hooks
134135
135- - ` src/testing.ts ` 提供仓库测试用注入 hooks,仅用于本仓库测试。
136- - 这些 hooks 属于 internal/unstable,不在包 exports 中,不承诺兼容性。
136+ - ` src/testing.ts ` provides test injection hooks for this repository only.
137+ - These hooks are internal/unstable, not part of package exports, and not covered by compatibility guarantees.
0 commit comments