A universal React-compatible render engine for building applications across multiple platforms
npx @tessl/cli install tessl/npm-rax@1.2.0Rax is a universal React-compatible render engine that enables developers to build applications that run across multiple platforms including Web, Weex, Node.js, Alibaba MiniApp, and WeChat MiniProgram. It provides a React-like API with better performance and smaller bundle size (~6KB) while maintaining full API compatibility with React components and hooks.
npm install raximport { createElement, render, Component, useState, useEffect } from 'rax';For CommonJS:
const { createElement, render, Component, useState, useEffect } = require('rax');React compatibility imports:
import { createElement, render, Component } from 'rax/dist/rax.js';
// or with compatibility layer
import Rax, { Children, isValidElement, createFactory, cloneElement } from 'rax/src/compat';Additional utilities (from compatibility layer):
import { Children, isValidElement, createFactory, cloneElement } from 'rax/src/compat';
// or as default export
const Rax = require('rax/src/compat');
// Rax.Children, Rax.isValidElement, etc.import { createElement, render, Component, useState } from 'rax';
import * as DriverDOM from 'driver-dom';
// Functional component with hooks
function Counter() {
const [count, setCount] = useState(0);
return createElement('div', null,
createElement('p', null, `Count: ${count}`),
createElement('button', {
onClick: () => setCount(count + 1)
}, 'Increment')
);
}
// Class component
class Greeting extends Component {
render() {
return createElement('h1', null, `Hello, ${this.props.name}!`);
}
}
// Render to DOM
render(
createElement('div', null,
createElement(Greeting, { name: 'World' }),
createElement(Counter)
),
document.body,
{ driver: DriverDOM }
);Rax is built around several key components:
createElement and element managementCore virtual DOM element creation and manipulation functionality. Essential for all Rax applications.
function createElement(type, config, ...children);
function Fragment(props);
function createRef();
function forwardRef(render);
function memo(type, compare);Class-based and functional component support with full lifecycle management and React compatibility.
class Component {
constructor(props, context);
setState(partialState, callback);
forceUpdate(callback);
}
class PureComponent extends Component {
constructor(props, context);
}Complete React hooks implementation for state management and side effects in functional components.
function useState(initialState);
function useEffect(effect, inputs);
function useContext(context);
function useRef(initialValue);
function useCallback(callback, inputs);
function useMemo(create, inputs);
function useReducer(reducer, initialArg, init);
function useLayoutEffect(effect, inputs);
function useImperativeHandle(ref, create, inputs);React-compatible context system for managing state across component trees without prop drilling.
function createContext(defaultValue);
interface ContextObject {
Provider: ComponentClass;
Consumer: ComponentClass;
_contextID: string;
_defaultValue: any;
__getNearestParentProvider: Function;
}Universal rendering engine that works across multiple platforms through pluggable driver system.
function render(element, container, options, callback);
function render(element, container, callback);Additional utilities for React compatibility, including children manipulation and element validation functions.
// From rax-children package
const Children: {
map(children, fn): Array;
forEach(children, fn): void;
count(children): number;
only(children): RaxElement;
toArray(children): Array;
};
// From rax-is-valid-element package
function isValidElement(object): boolean;
// From rax-create-factory package
function createFactory(type): Function;
// From rax-clone-element package
function cloneElement(element, props, ...children): RaxElement;Package version information for runtime version checking and debugging.
// Package version string (from process.env.RAX_VERSION at build time)
const version: string;Low-level utilities exposed for advanced use cases and platform driver development. These are internal APIs that may change between versions.
const shared: {
Host: Object; // Runtime state management
Instance: Object; // Instance management utilities
Element: Function; // Element constructor
flattenChildren: Function; // Children flattening utility
};Rax supports multiple platforms through its driver specification:
driver-dom for browser environments// Core element type
interface RaxElement {
type: string | Function;
key: string | null;
ref: Function | Object | null;
props: Object;
_owner: Component | null;
}
// Component props and context
interface ComponentProps {
[key: string]: any;
children?: RaxElement | RaxElement[];
}
interface ComponentContext {
[key: string]: any;
}
// Render options
interface RenderOptions {
driver: Object;
hydrate?: boolean;
parent?: RaxElement;
}
// Ref object
interface RefObject<T> {
current: T | null;
}