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
Built-in Libraries Overview
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
Using Hooks
Using Icons
Date Processing with dayjs
Utility Functions with lodash
Formula Calculations
Mathematical Expressions with math.js
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 withctx.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.Reactor calling Hooks, executeawait 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

