mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-19 11:24:57 -05:00
32 lines
786 B
TypeScript
32 lines
786 B
TypeScript
"use client";
|
|
|
|
import { useSyncExternalStore } from "react";
|
|
|
|
export type MobileNavigationView = "closed" | "docs" | "site";
|
|
|
|
let mobileNavigationView: MobileNavigationView = "closed";
|
|
const listeners = new Set<() => void>();
|
|
|
|
function subscribe(listener: () => void) {
|
|
listeners.add(listener);
|
|
return () => listeners.delete(listener);
|
|
}
|
|
|
|
function getSnapshot() {
|
|
return mobileNavigationView;
|
|
}
|
|
|
|
function getServerSnapshot(): MobileNavigationView {
|
|
return "closed";
|
|
}
|
|
|
|
export function setMobileNavigationView(view: MobileNavigationView) {
|
|
if (mobileNavigationView === view) return;
|
|
mobileNavigationView = view;
|
|
for (const listener of listeners) listener();
|
|
}
|
|
|
|
export function useMobileNavigationView() {
|
|
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
}
|