1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00
unleash.unleash/frontend/src/hooks/useLastViewedProject.ts

23 lines
579 B
TypeScript
Raw Normal View History

import { useEffect, useState } from 'react';
import { getLocalStorageItem, setLocalStorageItem } from '../utils/storage';
import { basePath } from 'utils/formatPath';
export const useLastViewedProject = () => {
const key = `${basePath}:unleash-lastViewedProject`;
const [lastViewed, setLastViewed] = useState(() => {
return getLocalStorageItem(key);
});
useEffect(() => {
if (lastViewed) {
setLocalStorageItem(key, lastViewed);
}
}, [lastViewed, key]);
return {
lastViewed,
setLastViewed,
};
};