# الإعداد

> كل خيار تأخذه init()، مع مثال كامل والإضافات المفعّلة افتراضيًا.

تأخذ `init` كائن إعدادات اختياريًا، فيه مفتاح واحد لكل إضافة.

## مثال كامل

يضبط هذا المثال كل الإضافات وكل الخيارات. تشرح صفحة كل إضافة خياراتها بالتفصيل.

*use-xerlock.ts*

```ts
import { open } from '@op-engineering/op-sqlite';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { useNavigationContainerRef } from '@react-navigation/native';
import { QueryClient } from '@tanstack/query-core';
import {
  callableAction,
  dispatchable,
  expoSqliteAdapter,
  init,
  opSqliteAdapter,
} from '@xerlock/client';
import * as Notifications from 'expo-notifications';
import * as SecureStore from 'expo-secure-store';
import * as SQLite from 'expo-sqlite';
import { useEffect } from 'react';
import { MMKV } from 'react-native-mmkv';

import { showNotification } from '../notifications/show-notification';
import { caseSlice, store, suspectsSlice } from '../redux/store';
import { useCaseStore, useSuspectStore } from '../zustand/stores';

const queryClient = new QueryClient();
const userPrefs = new MMKV({ id: 'user-prefs' });

export const useXerlock = () => {
  const navigationRef = useNavigationContainerRef();

  useEffect(() => {
    init({
      console: true,
      commands: true,
      network: {
        ignoreUrls: ['/health', /analytics/],
      },
      zustand: {
        stores: {
          case: useCaseStore,
          suspects: useSuspectStore,
        },
        historyLimit: 50,
        actions: [callableAction(useSuspectStore, 'addSuspect', ['Irene Adler'])],
      },
      redux: {
        store,
        actions: [
          caseSlice.actions,
          'app/reset',
          dispatchable(suspectsSlice.actions.added, { payload: 'Irene Adler' }),
        ],
      },
      storage: {
        asyncStorage: AsyncStorage,
        mmkv: { userPrefs },
        secureStore: SecureStore,
      },
      tanstackQuery: queryClient,
      database: {
        main: expoSqliteAdapter(SQLite.openDatabaseAsync('app.db')),
        cache: opSqliteAdapter(open({ name: 'cache.db' })),
      },
      navigation: { ref: navigationRef },
      notifications: {
        expoNotifications: Notifications,
        // Used instead of `expoNotifications` when both are set.
        onRemoteMessage: (message) => showNotification(message.notification),
      },
    });
  }, [navigationRef]);

  return navigationRef;
};
```

عرض المثال كاملًا

تنبيه

تحتاج إضافة `navigation` إلى المرجع من `useNavigationContainerRef()`، لذا استدعِ `init` من داخل `useEffect` في المكوّن الذي يعرض حاوية التنقل، ومرّر المرجع إلى تلك الحاوية أيضًا.

## الإضافات

| الإضافة                                         | يقبل                                       | مفعّل افتراضيًا |
| ----------------------------------------------- | ------------------------------------------ | --------------- |
| [`console`](/ar/docs/sdk/console/)              | `boolean`                                  | نعم             |
| [`commands`](/ar/docs/sdk/commands/)            | `boolean`                                  | نعم             |
| [`network`](/ar/docs/sdk/network/)              | `boolean \| NetworkPluginConfig`           | نعم             |
| [`tanstackQuery`](/ar/docs/sdk/tanstack-query/) | `false \| QueryClientLike`                 | لا              |
| [`zustand`](/ar/docs/sdk/zustand/)              | `false \| ZustandPluginConfig`             | لا              |
| [`redux`](/ar/docs/sdk/redux/)                  | `false \| ReduxPluginConfig`               | لا              |
| [`storage`](/ar/docs/sdk/storage/)              | `false \| StoragePluginConfig`             | لا              |
| [`database`](/ar/docs/sdk/database/)            | `false \| Record<string, DatabaseAdapter>` | لا              |
| [`navigation`](/ar/docs/sdk/navigation/)        | `false \| NavigationPluginConfig`          | لا              |
| [`notifications`](/ar/docs/sdk/notifications/)  | `false \| NotificationsPluginConfig`       | لا              |

## استدعاء init مرة أخرى

يستبدل استدعاء `init` مرة أخرى الإعدادات كاملة. يُعاد استخدام الاتصال بتطبيق سطح المكتب، لذا يمكنك استدعاؤها بأمان من `useEffect` يُعاد تشغيله.

## الأنواع

أنواع الإعدادات التي يصدّرها `@xerlock/client`:

* `XerlockConfig`
* `NetworkPluginConfig`
* `ZustandPluginConfig`
* `ReduxPluginConfig`
* `StoragePluginConfig`
* `NavigationPluginConfig`
* `NotificationsPluginConfig`
* `PluginOption`
* `PluginId`

نصيحة

لا تفعل `init` شيئًا في إصدارات الإنتاج، لذا يمكن إبقاء الإعدادات في مكانها.
