> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# Function: withInitDataInState()

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

## Type Parameters

| Type Parameter | Description                                     |
| -------------- | ----------------------------------------------- |
| `P`            | The type of the props of the wrapped component. |
| `S`            | The type of the state of the wrapped component. |

## Parameters

| Parameter | Type                        | Description                                   |
| --------- | --------------------------- | --------------------------------------------- |
| `App`     | `ComponentClass`\<`P`, `S`> | The class component to be wrapped by the HOC. |

## Returns

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

## Example

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

export default withInitDataInState(App);
```
