Skip to content

Commit

Permalink
Read settings during load
Browse files Browse the repository at this point in the history
  • Loading branch information
tnagorra committed Dec 23, 2024
1 parent 4623562 commit 3eb21ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import {
import useThrottledValue from '#hooks/useThrottledValue';
import { getWindowSize } from '#utils/common';
import { defaultConfigValue } from '#utils/constants';
import { getFromStorage } from '#utils/localStorage';
import { ConfigStorage } from '#utils/types';

import wrappedRoutes, { unwrappedRoutes } from './routes';

Expand Down Expand Up @@ -153,10 +155,14 @@ function App() {

// Local Storage

const [storageState, setStorageState] = useState<LocalStorageContextProps['storageState']>({
'timur-config': {
defaultValue: defaultConfigValue,
},
const [storageState, setStorageState] = useState<LocalStorageContextProps['storageState']>(() => {
const configValue = getFromStorage<ConfigStorage>('timur-config');
return ({
'timur-config': {
value: configValue,
defaultValue: defaultConfigValue,
},
});
});

const handleStorageStateUpdate: typeof setStorageState = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion src/PwaPrompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function PwaPrompt() {
},
onRegisterError: (error) => {
// eslint-disable-next-line no-console
console.info('SW registration error', error);
console.error('SW registration error', error);
},
});

Expand Down

0 comments on commit 3eb21ba

Please sign in to comment.