logologo
Get Started
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Italiano
Türkçe
Українська
Tiếng Việt
Bahasa Indonesia
ไทย
Polski
Nederlands
Čeština
العربية
עברית
हिन्दी
Svenska
Get Started
Guide
Development
Plugins
API
Home
logologo
RunJS Overview
Import Modules
Render in Container

Global Variables

window
document
navigator

ctx

ctx.blockModel
ctx.collection
ctx.collectionField
ctx.dataSource
ctx.dataSourceManager
ctx.element
ctx.exit()
ctx.exitAll()
ctx.filterManager
ctx.form
ctx.getModel()
ctx.getValue()
ctx.getVar()
ctx.i18n
ctx.importAsync()
ctx.initResource()
ctx.libs
ctx.location
ctx.logger
ctx.makeResource()
ctx.message
ctx.modal
ctx.model
ctx.notification
ctx.off()
ctx.on()
ctx.openView()
ctx.render()
ctx.request()
ctx.requireAsync()
ctx.resource
ctx.route
ctx.router
ctx.setValue()
ctx.sql
ctx.t()
ctx.view
Previous Pagectx.initResource()
Next Pagectx.location

#ctx.libs

ctx.libs is the unified namespace for RunJS built-in libraries (React, Ant Design, dayjs, lodash, etc.). No import or async loading; use ctx.libs.xxx directly.

#Use Cases

ScenarioDescription
JSBlock / JSField / JSItem / JSColumnReact + Ant Design for UI, dayjs for dates, lodash for data
Formulas / calculationsformula or math for Excel-like formulas and math expressions
Event flow / linkagelodash, dayjs, formula, etc. in logic-only code

#Built-in libraries

PropertyDescriptionDocs
ctx.libs.ReactReact core for JSX and HooksReact
ctx.libs.ReactDOMReactDOM (e.g. createRoot)React DOM
ctx.libs.antdAnt Design (Button, Card, Table, Form, Input, Modal, etc.)Ant Design
ctx.libs.antdIconsAnt Design icons (PlusOutlined, UserOutlined, etc.)@ant-design/icons
ctx.libs.dayjsDate/time utilitiesdayjs
ctx.libs.lodashUtilities (get, set, debounce, etc.)Lodash
ctx.libs.formulaExcel-like formulas (SUM, AVERAGE, IF, etc.)Formula.js
ctx.libs.mathMath expressions and evaluationMath.js

#Top-level aliases

For backward compatibility, some libs are also on ctx: ctx.React, ctx.ReactDOM, ctx.antd, ctx.dayjs. Prefer ctx.libs.xxx for consistency and docs.

#Lazy loading

lodash, formula, math are lazy-loaded: the first access to ctx.libs.lodash triggers a dynamic import, then the result is cached. React, antd, dayjs, antdIcons are preloaded in context.

#Examples

#React and Ant Design

const { Button, Card } = ctx.libs.antd;

ctx.render(
  <Card title="Title">
    <Button type="primary">Click</Button>
  </Card>
);

#Hooks

const { React } = ctx.libs;
const { useState } = React;
const { Button } = ctx.libs.antd;

const App = () => {
  const [count, setCount] = useState(0);
  return <Button onClick={() => setCount((c) => c + 1)}>{count}</Button>;
};
ctx.render(<App />);

#Icons

const { Button } = ctx.libs.antd;
const { UserOutlined, HeartOutlined } = ctx.libs.antdIcons;

ctx.render(<Button icon={<UserOutlined />}>User</Button>);

#dayjs

const now = ctx.libs.dayjs();
const formatted = now.format('YYYY-MM-DD HH:mm:ss');
ctx.message.info(formatted);

#lodash

const user = { profile: { name: 'Alice' } };
const name = ctx.libs.lodash.get(user, 'profile.name', 'Unknown');

#formula

const values = [1, 2, 3, 4];
const sum = ctx.libs.formula.SUM(values);
const avg = ctx.libs.formula.AVERAGE(values);

#math

const result = ctx.libs.math.evaluate('2 + 3 * 4');
// result === 14

#Notes

  • Mixing with ctx.importAsync: If you load external React via ctx.importAsync('react@19'), JSX uses that instance; do not mix with ctx.libs.antd. Load antd for that React version (e.g. ctx.importAsync('antd@5.x'), ctx.importAsync('@ant-design/icons@5.x')).
  • Multiple React instances: "Invalid hook call" or null hook dispatcher usually means multiple React instances. Before using ctx.libs.React or Hooks, run await ctx.importAsync('react@version') so the same React as the page is used.

#Related

  • ctx.importAsync(): load external ESM (e.g. specific React, Vue)
  • ctx.render(): render into container