astoilkov / use-local-storage-state

React hook that persists data in localStorage
MIT License
1.09k stars 39 forks source link

Additional type exports #42

Closed paulmelnikow closed 2 years ago

paulmelnikow commented 2 years ago

Hi there, and thanks for this great library! Have just upgraded from v6 to v15 and it seems to be working well.

Since createLocalStorageStateHook() has been removed and I was using it in one place, I replaced it with my own function, which I needed to annotate with my own types. I ended up checking this in:

export type UpdateState<T> = (newValue: T | ((value: T) => T)) => void
export type LocalStorageState<T> = [T, UpdateState<T>, LocalStorageProperties]
export interface LocalStorageProperties {
  isPersistent: boolean
  removeItem: () => void
}

Would you consider using / exporting these types from the package? I'd be happy to open a PR.

astoilkov commented 2 years ago

Great idea. Thanks! I will do it, no need for a PR. I will write you when I'm done.

astoilkov commented 2 years ago

Done. You can see the implementation and share your thoughts.

paulmelnikow commented 2 years ago

Wow, that looks great! And thanks so much! I look forward to giving it a try.

astoilkov commented 2 years ago

Great! I will make a new v16 release soon.