rooks
Version:
Essential React custom hooks ⚓ to super charge your components!
80 lines • 2.39 kB
TypeScript
/**
* useSuspenseNavigatorUserAgentData
* @description Suspense-enabled hook for getting high entropy values from Navigator User Agent Data API
* @see {@link https://rooks.vercel.app/docs/hooks/useSuspenseNavigatorUserAgentData}
*/
interface UADataValues {
brands?: Array<{
brand: string;
version: string;
}>;
mobile?: boolean;
platform?: string;
architecture?: string;
bitness?: string;
formFactors?: string[];
fullVersionList?: Array<{
brand: string;
version: string;
}>;
model?: string;
platformVersion?: string;
uaFullVersion?: string;
wow64?: boolean;
}
interface NavigatorUAData {
brands: Array<{
brand: string;
version: string;
}>;
mobile: boolean;
platform: string;
getHighEntropyValues(hints: string[]): Promise<UADataValues>;
toJSON(): object;
}
declare global {
interface Navigator {
userAgentData?: NavigatorUAData;
}
}
type HighEntropyHint = "architecture" | "bitness" | "formFactors" | "fullVersionList" | "model" | "platformVersion" | "uaFullVersion" | "wow64";
/**
* Clear all cached entries - useful for testing
* @internal
*/
export declare function clearCache(): void;
/**
* Suspense-enabled hook for getting high entropy values from Navigator User Agent Data API
*
* This hook will suspend (throw a promise) while the Navigator User Agent Data API
* is fetching high entropy values. It should be wrapped in a Suspense boundary.
*
* @param hints - Array of high entropy hints to request. Defaults to all available hints.
* @returns The high entropy values returned by the API
*
* @throws {Error} When Navigator User Agent Data API is not supported
* @throws {Promise} When data is still loading (for Suspense)
*
* @example
* ```tsx
* function MyComponent() {
* const userAgentData = useSuspenseNavigatorUserAgentData([
* "architecture",
* "platformVersion"
* ]);
*
* return <div>Architecture: {userAgentData.architecture}</div>;
* }
*
* function App() {
* return (
* <Suspense fallback={<div>Loading...</div>}>
* <MyComponent />
* </Suspense>
* );
* }
* ```
*/
declare function useSuspenseNavigatorUserAgentData(hints?: HighEntropyHint[]): UADataValues;
export { useSuspenseNavigatorUserAgentData };
//# sourceMappingURL=useSuspenseNavigatorUserAgentData.d.ts.map