@lynx-js/react

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.

React APIs

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.

Why is it based on compatibility with React 17?

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.

Documents

DocumentDescription
built-in-macros-
directives-

Classes

ClassDescription
Component-
MainThreadRefA MainThreadRef is 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 in current property of the MainThreadRef can be read and written in multiple main thread functions.
PureComponent-

Interfaces

InterfaceDescription
DataProcessorDefinitionDefinition of DataProcessor(s)
InitDataThe interface you can extends so that the defaultDataProcessor returning value can be customized
InitDataRawThe interface you can extends so that the defaultDataProcessor parameter can be customized
LynxAPIs under lynx global variable that added by ReactLynx.
RootThe default root exported by @lynx-js/react for you to render a JSX

Variables

VariableDescription
rootThe default and only root of ReactLynx for you to render JSX

Functions

FunctionDescription
createContextLets you create a Context that components can provide or read.
createElement-
createRef-
createRootThe default and only root of ReactLynx for you to render JSX
forwardRefLets your component expose an element node to a parent component using a ref.
FragmentLets you group elements without a wrapper node.
isValidElement-
lazyLets you defer loading a component’s code until it is rendered for the first time.
memoLets you skip re-rendering a component when its props are unchanged.
runOnBackgroundrunOnBackground allows triggering js functions on the js context asynchronously.
runOnMainThreadrunOnMainThread allows triggering main thread functions on the main thread asynchronously.
SuspenseLets you display a fallback until its children have finished loading.
useCallbackuseCallback will return a memoized version of the callback that only changes if one of the inputs has changed.
useContextAccepts 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.
useDebugValueuseDebugValue can be used to display a label for custom hooks in React DevTools.
useEffectAccepts a function that contains imperative, possibly effectful code.
useImperativeHandleuseImperativeHandle customizes the instance value that is exposed to parent components when using ref. As always, imperative code using refs should be avoided in most cases.
useInitDataA React Hooks for you to get initData. If initData is changed, a re-render will be triggered automatically.
useInitDataChangedA React Hooks for you to get notified when initData changed.
useLayoutEffectuseLayoutEffect is now an alias of useEffect. Use useEffect instead.
useLynxGlobalEventListeneruseLynxGlobalEventListener help you addListener as early as possible.
useMemouseMemo will only recompute the memoized value when one of the deps has changed.
useReducerAn alternative to useState.
useRefuseRef returns a mutable ref object whose .current property is initialized to the passed argument (initialValue). The returned object will persist for the full lifetime of the component.
useStateReturns a stateful value, and a function to update it.
useSyncExternalStore-
withInitDataInStateHigher-Order Component (HOC) that injects initData into the state of the given class component.

Components

FunctionDescription
InitDataConsumerThe Consumer Component that provide initData. This should be used with InitDataProvider
InitDataProviderThe Provider Component that provide initData, you must wrap your JSX inside it

Directives

DocumentDescription
directives-

Globals

DocumentDescription
built-in-macros-
Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.