logologo
Get Started
Tutorials
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Get Started
Tutorials
Guide
Development
Plugins
API
Home
logologo
RunJS Overview
Importing Modules
Rendering 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 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.

#Use Cases

ScenarioDescription
JSBlock / JSField / JSItem / JSColumnUse React + Ant Design to render UI, dayjs for date handling, and lodash for data processing.
Formula / CalculationUse formula or math for Excel-like formulas and mathematical expression operations.
Workflow / Linkage RulesCall utility libraries like lodash, dayjs, and formula in pure logic scenarios.

#Built-in Libraries Overview

PropertyDescriptionDocumentation
ctx.libs.ReactReact core, used for JSX and HooksReact
ctx.libs.ReactDOMReactDOM client API (including createRoot), used with React for renderingReact DOM
ctx.libs.antdAnt Design component library (Button, Card, Table, Form, Input, Modal, etc.)Ant Design
ctx.libs.antdIconsAnt Design icon library (e.g., PlusOutlined, UserOutlined)@ant-design/icons
ctx.libs.dayjsDate and time utility librarydayjs
ctx.libs.lodashUtility library (get, set, debounce, etc.)Lodash
ctx.libs.formulaExcel-like formula function library (SUM, AVERAGE, IF, etc.)Formula.js
ctx.libs.mathMathematical expression and calculation libraryMath.js

#Top-level Aliases

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.

#Lazy Loading

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.

#Examples

#Rendering with React and Ant Design

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

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

#Using 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 />);

#Using Icons

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

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

#Date Processing with dayjs

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

#Utility Functions with lodash

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

#Formula Calculations

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

#Mathematical Expressions with math.js

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

#Notes

  • Mixing with ctx.importAsync: If an external React is loaded via 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')).
  • Multiple React Instances: If "Invalid hook call" occurs or the hook dispatcher is null, it is usually caused by multiple React instances. Before reading ctx.libs.React or calling Hooks, execute await ctx.importAsync('react@version') first to ensure the same React instance is shared with the page.

#Related

  • ctx.importAsync() - Load external ESM modules on demand (e.g., specific versions of React, Vue)
  • ctx.render() - Render content to a container