@red-hat-developer-hub/backstage-plugin-bulk-import
Version:
35 lines (32 loc) • 983 B
JavaScript
import { useState, useCallback, useEffect } from 'react';
const STORAGE_KEY = "bulk-import-instructions-expanded";
function useInstructionsPreference(defaultExpanded) {
const [isExpanded, setIsExpanded] = useState(() => {
try {
const stored = localStorage.getItem(STORAGE_KEY);
return stored !== null ? JSON.parse(stored) : defaultExpanded;
} catch {
return defaultExpanded;
}
});
const setExpanded = useCallback((expanded) => {
setIsExpanded(expanded);
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(expanded));
} catch {
}
}, []);
useEffect(() => {
try {
const stored = localStorage.getItem(STORAGE_KEY);
if (stored === null) {
setIsExpanded(defaultExpanded);
}
} catch {
setIsExpanded(defaultExpanded);
}
}, [defaultExpanded]);
return [isExpanded, setExpanded];
}
export { useInstructionsPreference };
//# sourceMappingURL=useInstructionsPreference.esm.js.map