Fejlesztőknek
Kezdj bele
Témák/Theme SDK/Modules/navigation/Functions

Functions

Ez az oldal még csak angolul érhető el.

The functions of @poltura/theme-sdk/navigation.

Ezen az oldalon
import { … } from '@poltura/theme-sdk/navigation';

findCategory

Finds a category of the navigation tree by its id or by the path of its handles.

findCategory(nav: NavData, by: {
    readonly id: string;
} | {
    readonly path: readonly string[];
}): NavCategory | null

Parameters

  • nav: NavData: The tree, from useNavData.
  • by: { readonly id: string; } | { readonly path: readonly string[]; }: The category's id, or the handles from the top-level category down.

Returns: The category with its subcategories, or null when the tree has none such.

Example

import { findCategory, useNavData } from '@poltura/theme-sdk/navigation';

export function SubcategoryLinks({ id }: { id: string }) {
  const category = findCategory(useNavData(), { id });
  return (
    <ul>
      {category?.children.map((child) => (
        <li key={child.id}>
          <a href={child.href}>{child.name}</a>
        </li>
      ))}
    </ul>
  );
}
Utoljára frissítve