Skip to content

Commit

Permalink
#66 Export useLocalStorage return types
Browse files Browse the repository at this point in the history
  • Loading branch information
jharrilim committed Aug 2, 2020
1 parent d11364e commit 2b85b87
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/use-localstorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ function tryParse(value: string) {
}
}

export type LocalStorageNullableReturnValue<TValue> = [TValue | null, (newValue: TValue | null) => void, () => void];
export type LocalStorageReturnValue<TValue> = [TValue, (newValue: TValue | null) => void, () => void];

/**
* React hook to enable updates to state via localStorage.
* This updates when the {writeStorage} function is used, when the returned function
Expand All @@ -44,10 +47,8 @@ function tryParse(value: string) {
* associated with the key in position 0, a function to set the value in position 1,
* and a function to delete the value from localStorage in position 2.
*/
export function useLocalStorage<TValue = string>(key: string):
[TValue | null, (newValue: TValue | null) => void, () => void];
export function useLocalStorage<TValue = string>(key: string, defaultValue: TValue):
[TValue, (newValue: TValue | null) => void, () => void];
export function useLocalStorage<TValue = string>(key: string): LocalStorageNullableReturnValue<TValue>;
export function useLocalStorage<TValue = string>(key: string, defaultValue: TValue): LocalStorageReturnValue<TValue>;
export function useLocalStorage<TValue = string>(
key: string,
defaultValue: TValue | null = null,
Expand Down

0 comments on commit 2b85b87

Please sign in to comment.