rehooks / local-storage

React hook which syncs localStorage[key] with the comp.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unnecessary | null

ckknight opened this issue · comments

): [TValue | null, Dispatch<TValue>, Dispatch<void>] {

I believe useLocalStorage should have two separate exports:

export function useLocalStorage<TValue = string>(key: string): [TValue | null, (newValue: TValue) => void, () => void];
export function useLocalStorage<TValue = string>(key: string, initialValue: TValue): [TValue, (newValue: TValue) => void, () => void];

Notice the lack of | null on the second export, as it is guaranteed to be non-null by the specification of initialValue.

commented

That is correct. Good catch!