Skip to content

Commit

Permalink
feat(useUrlSearchParams): add write option (#2165)
Browse files Browse the repository at this point in the history
  • Loading branch information
waldonUB committed Sep 4, 2022
1 parent 48bf343 commit 7b2887e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/core/useUrlSearchParams/index.ts
Expand Up @@ -21,6 +21,13 @@ export interface UseUrlSearchParamsOptions<T> extends ConfigurableWindow {
* @default {}
*/
initialValue?: T

/**
* Write back to `window.history` automatically
*
* @default true
*/
write?: boolean
}

/**
Expand All @@ -38,6 +45,7 @@ export function useUrlSearchParams<T extends Record<string, any> = UrlParams>(
initialValue = {},
removeNullishValues = true,
removeFalsyValues = false,
write: enableWrite = true,
window = defaultWindow!,
} = options

Expand Down Expand Up @@ -126,6 +134,9 @@ export function useUrlSearchParams<T extends Record<string, any> = UrlParams>(
}

function onChanged() {
if (!enableWrite)
return

write(read(), true)
}

Expand Down

0 comments on commit 7b2887e

Please sign in to comment.