RunJS supports JSX syntax, allowing you to write code similar to React components. JSX is automatically compiled before execution.
ctx.libs.React.createElement and ctx.libs.React.Fragment.ctx.libs.React after compilation.ctx.importAsync('react@x.x.x'), JSX will switch to using the createElement method from that specific instance.RunJS includes React and common UI libraries built-in. You can access them directly via ctx.libs without using import:
createRoot if needed)When writing JSX directly, you don't need to destructure React. You only need to destructure from ctx.libs when using Hooks (such as useState, useEffect) or Fragment (<>...</>):
Note: Built-in React and external React imported via ctx.importAsync() cannot be mixed. If you use an external UI library, React must also be imported from the same external source.
When loading a specific version of React and UI libraries via ctx.importAsync(), JSX will use that React instance:
If antd depends on react/react-dom, you can specify the same version via deps to avoid multiple instances:
Note: When using external React, UI libraries like antd must also be imported via ctx.importAsync(). Do not mix them with ctx.libs.antd.
<Button type="primary">Text</Button><>...</> or <React.Fragment>...</React.Fragment> (requires destructuring const { React } = ctx.libs when using Fragment){expression} in JSX to insert variables or operations, such as {ctx.user.name} or {count + 1}. Do not use {{ }} template syntax.{flag && <span>Content</span>} or {flag ? <A /> : <B />}array.map() to return a list of elements, and ensure each element has a stable key.