-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IEN-930 | IEN-938 | Automatic page refresh is clearing BCCNM upload d…
…ata | Add variable pagination to the BCCNM/Inspire data review page (#665) * add session storage to avoid reload clean; modify page size; * fix formatting; * fix e2e page size error; * add back page size:5 because of e2e testing; * set pageSizes as optional props --------- Co-authored-by: Jerry Wang <jerryappleid761208@gmail.com>
- Loading branch information
1 parent
66b786e
commit 3d49957
Showing
6 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-disable no-console */ | ||
import { useState, useEffect } from 'react'; | ||
|
||
// Custom hook to handle session storage in a type-safe manner | ||
export function useSessionStorage<T>( | ||
key: string, | ||
initialValue: T, | ||
): [T, React.Dispatch<React.SetStateAction<T>>] { | ||
const [storedValue, setStoredValue] = useState<T>(() => { | ||
try { | ||
const item = sessionStorage.getItem(key); | ||
return item ? JSON.parse(item) : initialValue; | ||
} catch (error) { | ||
console.error('Failed to retrieve from sessionStorage', error); | ||
return initialValue; | ||
} | ||
}); | ||
|
||
useEffect(() => { | ||
try { | ||
sessionStorage.setItem(key, JSON.stringify(storedValue)); | ||
} catch (error) { | ||
console.error('Failed to save to sessionStorage', error); | ||
} | ||
}, [key, storedValue]); | ||
|
||
// Cleanup session storage on page left | ||
useEffect(() => { | ||
const handleCleanSessionStorage = () => { | ||
sessionStorage.removeItem(key); | ||
}; | ||
|
||
return () => { | ||
handleCleanSessionStorage(); | ||
}; | ||
}, [key]); | ||
|
||
return [storedValue, setStoredValue]; | ||
} |