ctx.libs is the unified namespace for built-in libraries in RunJS, containing commonly used libraries such as React, Ant Design, dayjs, and lodash. No import or asynchronous loading is required; they can be used directly via ctx.libs.xxx.
| Scenario | Description |
|---|---|
| JSBlock / JSField / JSItem / JSColumn | Use React + Ant Design to render UI, dayjs for date handling, and lodash for data processing. |
| Formula / Calculation | Use formula or math for Excel-like formulas and mathematical expression operations. |
| Workflow / Linkage Rules | Call utility libraries like lodash, dayjs, and formula in pure logic scenarios. |
| Property | Description | Documentation |
|---|---|---|
ctx.libs.React | React core, used for JSX and Hooks | React |
ctx.libs.ReactDOM | ReactDOM client API (including createRoot), used with React for rendering | React DOM |
ctx.libs.antd | Ant Design component library (Button, Card, Table, Form, Input, Modal, etc.) | Ant Design |
ctx.libs.antdIcons | Ant Design icon library (e.g., PlusOutlined, UserOutlined) | @ant-design/icons |
ctx.libs.dayjs | Date and time utility library | dayjs |
ctx.libs.lodash | Utility library (get, set, debounce, etc.) | Lodash |
ctx.libs.formula | Excel-like formula function library (SUM, AVERAGE, IF, etc.) | Formula.js |
ctx.libs.math | Mathematical expression and calculation library | Math.js |
For compatibility with legacy code, some libraries are also exposed at the top level: ctx.React, ctx.ReactDOM, ctx.antd, and ctx.dayjs. It is recommended to consistently use ctx.libs.xxx for easier maintenance and documentation searching.
lodash, formula, and math use lazy loading: a dynamic import is triggered only when ctx.libs.lodash is accessed for the first time, and the cache is reused thereafter. React, antd, dayjs, and antdIcons are pre-configured by the context and are available immediately.
ctx.importAsync('react@19'), JSX will use that instance. In this case, do not mix it with ctx.libs.antd. Ant Design must be loaded to match that React version (e.g., ctx.importAsync('antd@5.x'), ctx.importAsync('@ant-design/icons@5.x')).ctx.libs.React or calling Hooks, execute await ctx.importAsync('react@version') first to ensure the same React instance is shared with the page.