From 7631cc667966067be0d6efca7c217cf7cd173c7b Mon Sep 17 00:00:00 2001 From: Max Milton Date: Mon, 31 Jan 2022 17:41:03 +1000 Subject: [PATCH] feat: Allow useURLParams setter to take a function as the argument (#199) --- src/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 43fcd9d9..d40f41b1 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -171,11 +171,13 @@ export const useURLParams = (): [ * @param params - The new URL search query params to set. Properties set as * `undefined` will not be included in the URL. */ - (params: URLParams) => void, + (params: URLParams | ((prev: URLParams) => URLParams)) => void, ] => { const [params, set] = createSignal(decode(window.location.search.slice(1))); - const setParams = (urlParams: URLParams) => { + const setParams = ( + urlParams: ((prev: URLParams) => URLParams) | URLParams, + ) => { window.history.replaceState(null, '', encode(set(urlParams), '?')); };