Home > @lynx-js/react

react package

Classes

ClassDescription
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.

Functions

FunctionDescription
runOnBackground(f)runOnBackground allows triggering js functions on the background thread asynchronously.
runOnMainThread(fn)runOnMainThread allows triggering main thread functions on the main thread asynchronously.
useEffect(effect, deps)Accepts a function that contains imperative, possibly effectful code. The effects run after main thread dom update without blocking it.
useInitData()A React Hooks for you to get initData. If initData is changed, a re-render will be triggered automatically.
useInitDataChanged(callback)A React Hooks for you to get notified when initData changed.
useLayoutEffect(effect, deps)

useLayoutEffect is now an alias of useEffect. Use useEffect instead.

Accepts a function that contains imperative, possibly effectful code. The effects run after main thread dom update without blocking it.

useLynxGlobalEventListener(eventName, listener)useLynxGlobalEventListener help you addListener as early as possible.
useMainThreadRef(initValue)

Create A 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.

It is a hook and it should only be called at the top level of your component.

useMainThreadRef(initValue)

Create A 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.

It is a hook and it should only be called at the top level of your component.

useMainThreadRef()

Create A 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.

It is a hook and it should only be called at the top level of your component.

withInitDataInState(App)

Higher-Order Component (HOC) that injects initData into the state of the given class component.

This HOC checks if the provided component is a class component. If it is, it wraps the component and injects the initData into its state. It also adds a listener to update the state when data changes, and removes the listener when the component unmounts.

Interfaces

InterfaceDescription
DataProcessorDefinitionDefinition of DataProcessor(s)
InitData

The interface you can extends so that the defaultDataProcessor returning value can be customized

Should be used with lynx.registerDataProcessors. See more examples at Lynx.registerDataProcessors.

InitDataRaw

The interface you can extends so that the defaultDataProcessor parameter can be customized

Should be used with lynx.registerDataProcessors. See more examples at Lynx.registerDataProcessors.

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
InitDataConsumerThe Consumer Component that provide initData. This should be used with InitDataProvider Components
InitDataProviderThe Provider Component that provide initData, you must wrap your JSX inside it Components
rootThe default and only root of ReactLynx for you to render JSX