import {Meta} from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/functional/Composables/useApiManagementAsyncRef - Async API Management Initialization'/>

# `useApiManagementAsyncRef`

`useApiManagementAsyncRef` is an asynchronous wrapper for [`useApiManagementRef`](./useApiManagementRef.en.mdx) that performs immediate request initialization.

Unlike the standard `useApiManagementRef`, which initializes "lazily" (upon the first access to the list or data), this method calls `initSsr()` immediately upon creation. This makes it the ideal choice for use in SSR environments.

## Key Features
- **Immediate Initialization** — starts the GET request initialization process as soon as the hook is called.
- **SSR Support** — ensures data is loaded on the server before the page is sent to the client.
- **Full Management Functionality** — retains all features of `useApiManagementRef`, including formatters, search, and mutations.

## Parameters
Parameters are identical to [`useApiManagementRef`](./useApiManagementRef.en.mdx):

- `propsGet: ApiManagementGet<Return, Type>` — main GET request settings.
- `formattersOptions?: FormattersOptions` — formatting rules.
- `searchOptions?: ApiManagementSearch<Item, Columns>` — search settings.
- `postRequest / putRequest / deleteRequest` — mutation settings.
- `action?: (data: any) => Promise<void> | void` — a common callback to perform after any successful mutation.
- `apiInstance?: ApiInstance` — API instance.

## Returns
Returns an API management object. The return object structure is identical to [`useApiManagementRef`](./useApiManagementRef.en.mdx):

- `isValid: ComputedRef<boolean>` — `true` if data matches `typeData` check.
- `isResponseContractValid: ComputedRef<boolean>` — `true` if the response data matches the defined contract.
- `responseValidationResult: ComputedRef<ApiDataValidation | undefined>` — detailed result of the contract validation.
- `list: ComputedRef` — processed data array with support for Skeleton, formatters, and search.
- `data: ComputedRef<ApiData<Return> | undefined>` — raw reactive data from `useApiRef`.
- `errorItem: ComputedRef<ApiErrorItem | undefined>` — current error object if the request failed.
- `length: ComputedRef<number>` — current length of the `list`.
- `starting / loading / reading` — request status flags.
- `loadingSearch / loadingPost / loadingPut / loadingDelete` — loading states for search and mutations.
- `isSearch / search` — search status and reactive search string.
- `sendPost / sendPut / sendDelete` — mutation execution methods.
- `reset / abort` — control methods.

## Example

```typescript
import { useApiManagementAsyncRef } from '@dxtmisha/functional'

// Initialization (and SSR pre-fetching) starts immediately
const { list, loading } = useApiManagementAsyncRef(
  { 
    path: 'api/products',
    skeleton: () => Array(3).fill({ id: 0, title: 'Loading...' })
  }
)
```
