-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuseConfig.jsx
More file actions
23 lines (22 loc) · 882 Bytes
/
Copy pathuseConfig.jsx
File metadata and controls
23 lines (22 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { useQuery } from "@tanstack/react-query";
import configRepository from "../repositories/ConfigRepository";
/**
* Hook to fetch and cache application configuration
*
* Configuration values are set at container startup and never change during runtime,
* so they are cached indefinitely (staleTime: Infinity)
*
* @returns {Object} Query result
* @returns {Object} data - Config data: { userType: 'admin' | 'member' | 'viewer' }
* @returns {boolean} isLoading - Loading state
* @returns {Error} error - Error if request failed
*/
export const useConfig = () => {
return useQuery({
queryKey: ["config"],
queryFn: () => configRepository.getConfig(),
staleTime: Infinity, // Config never goes stale (set at container startup)
gcTime: Infinity, // Keep in cache forever
retry: 3, // Retry failed requests (important for app initialization)
});
};