eslint: enable react-hooks checks

Also fix all errors, which can lead to subtile bugs.

Mostly fixings deps and refactoring to make typescript happy.
This commit is contained in:
David Lechner
2022-12-17 13:56:01 -06:00
committed by David Lechner
parent ee466ac904
commit 9d71bb4734
15 changed files with 321 additions and 269 deletions
+17 -13
View File
@@ -27,25 +27,29 @@ export function useAppLastDocsPageSetting() {
// mirror session storage value to local storage
useEffect(() => {
setLastPageGlobalSetting(lastPageSessionSetting);
}, [lastPageSessionSetting]);
}, [lastPageSessionSetting, setLastPageGlobalSetting]);
// the way the docs control works, we only provide the initial page, then
// it manages navigation after that, so we only want the initial of this
// value when the app first starts
const initialDocsPage = useMemo(() => {
try {
const url = new URL(lastPageSessionSetting);
const initialDocsPage = useMemo(
() => {
try {
const url = new URL(lastPageSessionSetting);
// in case someone is hacking the storage value directly
if (!url.pathname.startsWith(`/${docsPathPrefix}`)) {
throw new Error('invalid or outdated path');
// in case someone is hacking the storage value directly
if (!url.pathname.startsWith(`/${docsPathPrefix}`)) {
throw new Error('invalid or outdated path');
}
return lastPageSessionSetting;
} catch {
return defaultPage;
}
return lastPageSessionSetting;
} catch {
return defaultPage;
}
}, []);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[], // no deps so that we only get the initial value
);
return { initialDocsPage, setLastDocsPage: setLastPageSessionSetting };
}