> For the complete documentation index, see [llms.txt](https://phoenixcoded.gitbook.io/able-pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://phoenixcoded.gitbook.io/able-pro/react/how-tos/render-menu-from-the-backend.md).

# Render Menu from the backend

{% tabs %}
{% tab title="VITE (TS)" %}
Able Pro is already rendering the menu from the backend. The dashboard menus (Default, Analytics) are rendered via the back end.

You can check the Fack backend API here that we used to render <https://github.com/phoenixcoded20/mock-data-api-nextjs>

To add a menu from the backend, you can follow the steps below:

1. Open the file menu.ts *(src/api/menu.ts)*, and edit the API URL in the useGetMenu function.

{% code title="src/api/menu.ts" %}

```typescript
const endpoints = {
  key: 'api/menu',
  master: 'master',
  dashboard: '/dashboard' // server URL
};

export function useGetMenu() {
  const { data, isLoading, error, isValidating } = useSWR(endpoints.key + endpoints.dashboard, fetcher, {
    revalidateIfStale: false,
    revalidateOnFocus: false,
    revalidateOnReconnect: false
  });

  const memoizedValue = useMemo(() => {
    let updatedMenu = data?.dashboard;

    if (updatedMenu && Array.isArray(updatedMenu.children) && updatedMenu.children.length > 0) {
      updatedMenu = {
        ...updatedMenu,
        children: updatedMenu.children.map((group: NavItemType) => {
          if (Array.isArray(group.children)) {
            return {
              ...group,
              children: [...group.children, staticMenuItem]
            };
          }
          return group;
        })
      };
    }

    return {
      menu: updatedMenu as NavItemType,
      menuLoading: isLoading,
      menuError: error,
      menuValidating: isValidating,
      menuEmpty: !isLoading && !data?.length
    };
  }, [data, error, isLoading, isValidating]);

  return memoizedValue;
}
```

{% endcode %}

2. Add file **menu.tsx** in src/menu-items, and copy code from dashboard.tsx (src/menu-items/). Set icons and local files according to the API response.
3. Open the file index.tsx *(*&#x73;rc/layout/Dashboard/Drawer/DrawerContent/Navigation/index.ts&#x78;*)*, and add the code below the line.

{% code title="src/layout/Dashboard/Drawer/DrawerContent/Navigation/index.tsx" %}

```typescript
import { useGetMenu } from 'api/menu';
...
import menuItem from 'menu-items';
import { MenuFromAPI } from 'menu-items/dashboard';
...

function isFound(arr: any, str: string) {
  return arr.items.some((element: any) => {
    if (element.id === str) {
      return true;
    }
    return false;
  });
}

// ==============================|| DRAWER CONTENT - NAVIGATION ||============================== //

export default function Navigation() {
  const { menuLoading } = useGetMenu();
  const [menuItems, setMenuItems] = useState<{ items: NavItemType[] }>({ items: [] });
 
  let dashboardMenu = MenuFromAPI();
  useLayoutEffect(() => {
    if (menuLoading && !isFound(menuItem, 'group-dashboard-loading')) {
      menuItem.items.splice(0, 0, dashboardMenu);
      setMenuItems({ items: [...menuItem.items] });
    } else if (!menuLoading && dashboardMenu?.id !== undefined && !isFound(menuItem, 'group-dashboard')) {
      menuItem.items.splice(0, 1, dashboardMenu);
      setMenuItems({ items: [...menuItem.items] });
    } else {
      setMenuItems({ items: [...menuItem.items] });
    }
    // eslint-disable-next-line
  }, [menuLoading]);

  ...
}
```

{% endcode %}
{% endtab %}

{% tab title="VITE (JS)" %}
Able Pro is already rendering the menu from the backend. The dashboard menus (Default, Analytics) are rendered via the back end.

You can check the Fack backend API here that we used to render the menu: <https://github.com/phoenixcoded20/mock-data-api-nextjs>

To add a menu from the backend, you can follow the steps below:

1. Open the file menu.ts *(src/api/menu.js)*, and edit the API URL in the useGetMenu function.

{% code title="src/api/menu.js" %}

```javascript
const endpoints = {
  key: 'api/menu',
  master: 'master',
  dashboard: '/dashboard' // server URL
};

export function useGetMenu() {
  const { data, isLoading, error, isValidating } = useSWR(endpoints.key + endpoints.dashboard, fetcher, {
    revalidateIfStale: false,
    revalidateOnFocus: false,
    revalidateOnReconnect: false
  });

  const memoizedValue = useMemo(() => {
    let updatedMenu = data?.dashboard;

    if (updatedMenu && Array.isArray(updatedMenu.children) && updatedMenu.children.length > 0) {
      updatedMenu = {
        ...updatedMenu,
        children: updatedMenu.children.map((group) => {
          if (Array.isArray(group.children)) {
            return {
              ...group,
              children: [...group.children, staticMenuItem]
            };
          }
          return group;
        })
      };
    }

    return {
      menu: updatedMenu,
      menuLoading: isLoading,
      menuError: error,
      menuValidating: isValidating,
      menuEmpty: !isLoading && !data?.length
    };
  }, [data, error, isLoading, isValidating]);

  return memoizedValue;
j
```

{% endcode %}

2. Add file **menu.jsx** in src/menu-items, and copy code from dashboard.jsx (src/menu-items/). Set icons and local files according to the API response.
3. Open the file index.jsx *(*&#x73;rc/layout/Dashboard/Drawer/DrawerContent/Navigation/index.js&#x78;*)*, and add the code below the line.

{% code title="src/layout/Dashboard/Drawer/DrawerContent/Navigation/index.jsx" %}

```javascript
import { useGetMenu } from 'api/menu';
..
import menuItem from 'menu-items';
import { MenuFromAPI } from 'menu-items/dashboard';
...

function isFound(arr, str) {
  return arr.items.some((element) => {
    if (element.id === str) {
      return true;
    }
    return false;
  });
}

// ==============================|| DRAWER CONTENT - NAVIGATION ||============================== //

export default function Navigation() {

  const { menuLoading } = useGetMenu();
  const [menuItems, setMenuItems] = useState({ items: [] });
 
  let dashboardMenu = MenuFromAPI();
  useLayoutEffect(() => {
    if (menuLoading && !isFound(menuItem, 'group-dashboard-loading')) {
      menuItem.items.splice(0, 0, dashboardMenu);
      setMenuItems({ items: [...menuItem.items] });
    } else if (!menuLoading && dashboardMenu?.id !== undefined && !isFound(menuItem, 'group-dashboard')) {
      menuItem.items.splice(0, 1, dashboardMenu);
      setMenuItems({ items: [...menuItem.items] });
    } else {
      setMenuItems({ items: [...menuItem.items] });
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [menuLoading]);

  ...
}
```

{% endcode %}
{% endtab %}
{% endtabs %}
