Skip to content

Commit

Permalink
fix: useStorageState type
Browse files Browse the repository at this point in the history
  • Loading branch information
awmleer committed Dec 15, 2020
1 parent 1e417b3 commit 62ded21
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/hooks/src/createUseStorageState/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ export interface IFuncStorage {
(): Storage;
}

export type StorageStateDefaultValue<T> = T | IFuncUpdater<T>;

export type StorageStateResult<T> = [T | undefined, (value: StorageStateDefaultValue<T>) => void];
export type StorageStateResult<T> = [T | undefined, (value?: T | IFuncUpdater<T>) => void];

function isFunction<T>(obj: any): obj is T {
return typeof obj === 'function';
Expand All @@ -20,7 +18,7 @@ function isFunction<T>(obj: any): obj is T {
export function createUseStorageState(nullishStorage: Storage | null) {
function useStorageState<T>(
key: string,
defaultValue?: StorageStateDefaultValue<T>,
defaultValue?: T | IFuncUpdater<T>,
): StorageStateResult<T> {
const storage = nullishStorage as Storage;
const [state, setState] = useState<T | undefined>(() => getStoredValue());
Expand Down

0 comments on commit 62ded21

Please sign in to comment.