mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 10:35:11 +00:00
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:
committed by
David Lechner
parent
ee466ac904
commit
9d71bb4734
+17
-13
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user