useBottomSheetHistory
useBottomSheetHistory syncs a Bottom Sheet’s open state with the browser history
stack. When the sheet opens, it pushes a hash entry. When the user presses the
back button, the hook can close the sheet.
Each hook instance gets a session-scoped index stored in sessionStorage under
plainsheet-hash-index.
Interface
useBottomSheetHistory: (options: UseBottomSheetHistoryOptions) =>
UseBottomSheetHistoryReturn;Options
type UseBottomSheetHistoryOptions = {
isOpen: boolean;
onClose: () => void;
enabled?: boolean;
hashPrefix?: string;
};isOpen: Current open state fromuseBottomSheet.onClose: Callback to close the sheet (usuallybottomSheet.close).hashPrefix: When provided, hash becomes#bottom-sheet-{hashPrefix}-{index}. Without it, hash is#bottom-sheet-{index}.id: Optional stable id for the sheet. If omitted, a unique id is generated.
Returns
type UseBottomSheetHistoryReturn = {
id: string;
hash: string;
hasPushed: boolean;
isTopmost: boolean;
};