Welcome to the API reference for @lynx-js/react, the package that provides the ReactLynx framework. For an introduction to ReactLynx, please visit the ReactLynx Guides.
ReactLynx is based on the React 17 API. You can expect the React APIs provided by @lynx-js/react to be fully compatible with React 17 or Preact.
Here is an overview of the APIs provided by ReactLynx. These APIs will behave consistently with those described in the official React reference unless otherwise specified. We will also highlight any special considerations for using them on the Lynx platform.
React officially entered the "concurrent" era starting with React 18. Concurrent React features, represented by APIs such as useTransition and useDeferredValue, have very strict requirements for the scheduling method and concurrency model of the execution environment—including dependencies on or overwriting of browser Web APIs, dependencies on the new architecture of React Native, and more. Lynx has its own characteristics and considerations in architectural evolution, so we chose React 17 as the foundation for ReactLynx, evolving into the Lynx system while retaining the React programming model.
At the same time, we will continue to pay attention to subsequent React advancements, such as React 19 and React Compiler, and attempt to integrate the parts that do not depend on the concurrent architecture into the ReactLynx system.
| Document | Description | 
|---|---|
| built-in-macros | - | 
| directives | - | 
| Class | Description | 
|---|---|
| Component | - | 
| MainThreadRef | A MainThreadRefis a ref that can only be accessed on the main thread. It is used to preserve states between main thread function calls. The data saved incurrentproperty of theMainThreadRefcan be read and written in multiple main thread functions. | 
| PureComponent | - | 
| Interface | Description | 
|---|---|
| DataProcessorDefinition | Definition of DataProcessor(s) | 
| InitData | The interface you can extends so that the defaultDataProcessorreturning value can be customized | 
| InitDataRaw | The interface you can extends so that the defaultDataProcessorparameter can be customized | 
| Lynx | APIs under lynxglobal variable that added by ReactLynx. | 
| Root | The default root exported by @lynx-js/reactfor you to render a JSX | 
| Variable | Description | 
|---|---|
| root | The default and only root of ReactLynx for you to render JSX | 
| Function | Description | 
|---|---|
| createContext | Lets you create a Context that components can provide or read. | 
| createElement | - | 
| createRef | - | 
| createRoot | The default and only root of ReactLynx for you to render JSX | 
| forwardRef | Lets your component expose an element node to a parent component using a ref. | 
| Fragment | Lets you group elements without a wrapper node. | 
| isValidElement | - | 
| lazy | Lets you defer loading a component’s code until it is rendered for the first time. | 
| memo | Lets you skip re-rendering a component when its props are unchanged. | 
| runOnBackground | runOnBackgroundallows triggering js functions on the js context asynchronously. | 
| runOnMainThread | runOnMainThreadallows triggering main thread functions on the main thread asynchronously. | 
| Suspense | Lets you display a fallback until its children have finished loading. | 
| useCallback | useCallbackwill return a memoized version of the callback that only changes if one of theinputshas changed. | 
| useContext | Accepts a context object (the value returned from React.createContext) and returns the current context value, as given by the nearest context provider for the given context. | 
| useDebugValue | useDebugValuecan be used to display a label for custom hooks in React DevTools. | 
| useEffect | Accepts a function that contains imperative, possibly effectful code. | 
| useImperativeHandle | useImperativeHandlecustomizes the instance value that is exposed to parent components when usingref. As always, imperative code using refs should be avoided in most cases. | 
| useInitData | A React Hooks for you to get initData. IfinitDatais changed, a re-render will be triggered automatically. | 
| useInitDataChanged | A React Hooks for you to get notified when initDatachanged. | 
| useLayoutEffectis now an alias ofuseEffect. UseuseEffectinstead. | |
| useLynxGlobalEventListener | useLynxGlobalEventListenerhelp youaddListeneras early as possible. | 
| useMemo | useMemowill only recompute the memoized value when one of thedepshas changed. | 
| useReducer | An alternative to useState. | 
| useRef | useRefreturns a mutable ref object whose.currentproperty is initialized to the passed argument (initialValue). The returned object will persist for the full lifetime of the component. | 
| useState | Returns a stateful value, and a function to update it. | 
| useSyncExternalStore | - | 
| withInitDataInState | Higher-Order Component (HOC) that injects initDatainto the state of the given class component. | 
| Function | Description | 
|---|---|
| InitDataConsumer | The Consumer Component that provide initData. This should be used with InitDataProvider | 
| InitDataProvider | The Provider Component that provide initData, you must wrap your JSX inside it | 
| Document | Description | 
|---|---|
| directives | - | 
| Document | Description | 
|---|---|
| built-in-macros | - |