Skip to content

Commit

Permalink
Revert "✨ new storeDefault option #1"
Browse files Browse the repository at this point in the history
This reverts commit e666bcb.
  • Loading branch information
astoilkov committed Aug 7, 2024
1 parent e666bcb commit f8f7650
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
8 changes: 0 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,6 @@ Default: `true`

Setting to `false` doesn't subscribe to the [Window storage event](https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event). If you set to `false`, updates won't be synchronized across tabs, windows and iframes.

#### `options.storeDefault`

Type: `boolean`

Default: `false`

Setting to `true` calls `storage.setItem()` for the default value so the default value is persisted in `Storage` after the first render of the hook.

#### `options.serializer`

Type: `{ stringify, parse }`
Expand Down
5 changes: 1 addition & 4 deletions src/useStorageState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export type StorageStateOptions<T> = {
defaultValue?: T | (() => T)
storage?: Storage
sync?: boolean
storeDefault?: boolean
serializer?: {
stringify: (value: unknown) => string
parse: (value: string) => unknown
Expand Down Expand Up @@ -43,7 +42,6 @@ export default function useStorageState<T = undefined>(
defaultValue,
options?.storage,
options?.sync,
options?.storeDefault,
serializer?.parse,
serializer?.stringify,
)
Expand All @@ -54,7 +52,6 @@ function useStorage<T>(
defaultValue: T | undefined,
storage: Storage = goodTry(() => localStorage) ?? sessionStorage,
sync: boolean = true,
storeDefault: boolean = false,
parse: (value: string) => unknown = parseJSON,
stringify: (value: unknown) => string = JSON.stringify,
): StorageState<T | undefined> {
Expand Down Expand Up @@ -104,7 +101,7 @@ function useStorage<T>(
// issues that were caused by incorrect initial and secondary implementations:
// - https://github.com/astoilkov/use-local-storage-state/issues/30
// - https://github.com/astoilkov/use-local-storage-state/issues/33
if (storeDefault && defaultValue !== undefined && string === null) {
if (defaultValue !== undefined && string === null) {
// reasons for `localStorage` to throw an error:
// - maximum quota is exceeded
// - under Mobile Safari (since iOS 5) when the user enters private mode
Expand Down

0 comments on commit f8f7650

Please sign in to comment.