@lynx-js/react / withInitDataInState

函数: withInitDataInState()

function withInitDataInState<P, S>(App: ComponentClass<P, S>): ComponentClass<P, S>

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.

类型参数

类型参数描述
PThe type of the props of the wrapped component.
SThe type of the state of the wrapped component.

参数

范围类型描述
AppComponentClass<P, S>The class component to be wrapped by the HOC.

返回

ComponentClass<P, S>

The original component if it is not a class component, otherwise a new class component with initData injection and state update functionality.

示例

class App extends React.Component<MyProps, MyState> {
  // component implementation
}

export default withInitDataInState(App);

定义于

@lynx-js/react/runtime/lib/core/initData.d.ts:44

除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。