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

24 lines
651 B
TypeScript
Raw Normal View History

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