mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
24 lines
651 B
TypeScript
24 lines
651 B
TypeScript
|
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,
|
||
|
};
|
||
|
};
|