import { Checkbox, Text, useCheckboxGroup } from "@vortexlabs/vortex-native";
const SelectedCount = () => {
const group = useCheckboxGroup();
if (!group) return null;
return <Text>Selected: {group.value.length}</Text>;
};
export const Example = () => (
<Checkbox.Group ariaLabel="Notifications" defaultValue={["email"]}>
<Checkbox.GroupLabel>Notifications</Checkbox.GroupLabel>
<Checkbox.Item value="email" label="Email" />
<Checkbox.Item value="push" label="Push" />
<SelectedCount />
</Checkbox.Group>
);Features
- Reads the closest group's selection and shared state.
- Updates when the group value changes.
- Returns
nulloutside the group.
Group Context
Call useCheckboxGroup() without arguments from a descendant of Checkbox.Group. Inside the group, value is an empty array when nothing is selected.
A component that renders the group must put the hook in a child to read its selection. Use Checkbox.Item for selectable controls. It handles presses and announces the checked state.