Skip to content

Commit 97d9cb1

Browse files
committed
fix: relax persistence type contraints
1 parent 2ccb2e5 commit 97d9cb1

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

lib/SettingsContext.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function deserializeSettingsState(state: SerializedSettingsState): SettingsState
5252

5353
const SettingsStateContext = createContext<SettingsStateContextType>({
5454
state: initialState,
55-
set: () => {},
55+
set: () => { },
5656
});
5757

5858
const SettingsStateProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
@@ -63,8 +63,6 @@ const SettingsStateProvider: React.FC<{ children: React.ReactNode }> = ({ childr
6363

6464
const deserializedState = useMemo(() => deserializeSettingsState(state), [state]);
6565

66-
console.info({ deserializedState });
67-
6866
const setSettingsState = useCallback(
6967
(dispatch: SetStateAction<SettingsState>) => {
7068
if (typeof dispatch === 'function') {

lib/persistence.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
import { Dispatch, SetStateAction, useState } from 'react';
44

5-
type JsonPrimitive = string | number | boolean | null;
6-
type JsonArray = JsonValue[];
7-
type JsonObject = { [key: string]: JsonValue };
8-
type JsonValue = JsonPrimitive | JsonArray | JsonObject;
9-
10-
function saveToLocalStorage<T extends JsonValue>(key: string, value: T): void {
5+
function saveToLocalStorage<T extends object>(key: string, value: T): void {
116
if (typeof localStorage === 'undefined') {
127
console.error('Local storage is not available.');
138
return;
@@ -25,7 +20,7 @@ function saveToLocalStorage<T extends JsonValue>(key: string, value: T): void {
2520
}
2621
}
2722

28-
function loadFromLocalStorage<T extends JsonValue>(key: string): T | undefined {
23+
function loadFromLocalStorage<T extends object>(key: string): T | undefined {
2924
if (typeof localStorage === 'undefined') {
3025
console.error('Local storage is not available.');
3126
return undefined;
@@ -44,7 +39,7 @@ function loadFromLocalStorage<T extends JsonValue>(key: string): T | undefined {
4439
}
4540
}
4641

47-
export function createLocalStorageInterface<T extends JsonValue>(
42+
export function createLocalStorageInterface<T extends object>(
4843
key: string,
4944
): { load: () => T | undefined; save: (value: T) => void } {
5045
return {
@@ -53,7 +48,7 @@ export function createLocalStorageInterface<T extends JsonValue>(
5348
};
5449
}
5550

56-
export function usePersistToLocalStorage<T extends JsonValue>(
51+
export function usePersistToLocalStorage<T extends object>(
5752
key: string,
5853
initialValue: T,
5954
): [T, Dispatch<SetStateAction<T>>] {

0 commit comments

Comments
 (0)