Skip to main content

useAccordionItem

useAccordionItem is a hook that reads an Accordion section’s state, such as whether a custom header should say Show or Hide.

Import

import { useAccordionItem } from '@vortexlabs/vortex-native';
import { Accordion, Stack, Text, useAccordionItem } from "@vortexlabs/vortex-native";

const DeliveryLabel = () => {
  const { active } = useAccordionItem();
  return <Text weight="semibold">{active ? "Hide delivery details" : "Show delivery details"}</Text>;
};

export const AccordionItemState = () => (
  <Stack width={340} maxWidth="100%">
    <Accordion.Root>
      <Accordion.Item value="delivery" label={<DeliveryLabel />}>
        <Text>Your order ships in two business days.</Text>
      </Accordion.Item>
    </Accordion.Root>
  </Stack>
);

Features

  • Reports whether the nearest item is open and whether its trigger is disabled.
  • Updates when that item’s state changes.

Item State

Call the hook inside an Accordion.Item. active is true while its panel is open. disabled is true while the item’s trigger is disabled.