Files
nutriscan/hooks/useCacheOnlyMode.ts
Evandro Fonseca Junior c173fec668 feat(api): implement product caching mechanism
- Add NODE_ENV=production to .env for environment configuration
- Enhance product API route with JSON cache manager for local storage and retrieval
- Introduce cache-only mode and detailed logging for better performance and offline support
- Update UI to display cache status and storage statistics
2025-10-09 04:30:46 -03:00

31 lines
757 B
TypeScript

"use client";
import { useState, useEffect } from "react";
export function useCacheOnlyMode() {
const [cacheOnly, setCacheOnly] = useState(false);
const isProd = process.env.NODE_ENV === "production";
useEffect(() => {
if (isProd) {
const saved = localStorage.getItem("cache_only_mode");
setCacheOnly(saved === "true");
}
}, [isProd]);
useEffect(() => {
const handleStorageChange = () => {
const saved = localStorage.getItem("cache_only_mode");
setCacheOnly(saved === "true");
};
window.addEventListener("storage", handleStorageChange);
return () => window.removeEventListener("storage", handleStorageChange);
}, []);
return {
cacheOnly: isProd ? cacheOnly : false,
isProd,
};
}