欢迎来到 @lynx-js/react
的 API 参考文档,这个包提供了 ReactLynx 框架。如需了解 ReactLynx 的入门介绍,请访问 ReactLynx 指南。
ReactLynx 以 React 17 API 作为基础。你可以期待 @lynx-js/react
提供的 React APIs 与 React 17 或 Preact 完全兼容。
以下是 ReactLynx 提供的 API 一览。如无特殊说明,这些 API 将和 React 官方参考 行为一致,否则我们将重点描述其在 Lynx 平台中的注意事项。
React 从 React 18 开始正式进入「并发」时代。以 useTransition
、useDeferredValue
这些 API 为代表的「并发 React 功能」对执行环境的调度方式和并发模型有着非常苛刻的要求 —— 包括依赖或覆写浏览器 Web API、依赖 React Native 新架构等。Lynx 在架构演进上有自己的特点和思考,因此我们选择了 React 17 作为 ReactLynx 的基石,在保留 React 编程模型的前提下,向 Lynx 体系演进。
于此同时,我们也会继续关注 React 19 与 React Compiler 等后续 React 演进中不依赖并发架构的部分,并尝试将其整合进 ReactLynx 体系中。
Document | 描述 |
---|---|
built-in-macros | - |
directives | - |
Class | 描述 |
---|---|
Component | - |
MainThreadRef | A 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 | - |
Interface | 描述 |
---|---|
DataProcessorDefinition | Definition of DataProcessor(s) |
InitData | The interface you can extends so that the defaultDataProcessor returning value can be customized |
InitDataRaw | The interface you can extends so that the defaultDataProcessor parameter can be customized |
Lynx | APIs under lynx global variable that added by ReactLynx. |
Root | The default root exported by @lynx-js/react for you to render a JSX |
Variable | 描述 |
---|---|
root | The default and only root of ReactLynx for you to render JSX |
Function | 描述 |
---|---|
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 | runOnBackground allows triggering js functions on the js context asynchronously. |
runOnMainThread | runOnMainThread allows triggering main thread functions on the main thread asynchronously. |
Suspense | Lets you display a fallback until its children have finished loading. |
useCallback | useCallback will return a memoized version of the callback that only changes if one of the inputs has 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 | useDebugValue can be used to display a label for custom hooks in React DevTools. |
useEffect | Accepts a function that contains imperative, possibly effectful code. |
useImperativeHandle | useImperativeHandle 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. |
useInitData | A React Hooks for you to get initData . If initData is changed, a re-render will be triggered automatically. |
useInitDataChanged | A React Hooks for you to get notified when initData changed. |
The signature is identical to useEffect , but it fires synchronously after all element mutations. Use this to read layout from the element and synchronously re-render. Updates scheduled inside useLayoutEffect will be flushed synchronously, before the browser has a chance to paint. |
|
useLynxGlobalEventListener | useLynxGlobalEventListener help you addListener as early as possible. |
useMainThreadRef | Create A MainThreadRef . |
useMemo | useMemo will only recompute the memoized value when one of the deps has changed. |
useReducer | An alternative to useState . |
useRef | useRef 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. |
useState | Returns a stateful value, and a function to update it. |
useSyncExternalStore | - |
withInitDataInState | Higher-Order Component (HOC) that injects initData into the state of the given class component. |
Function | 描述 |
---|---|
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 | 描述 |
---|---|
directives | - |
Document | 描述 |
---|---|
built-in-macros | - |