Skip to content

Commit

Permalink
feat: Allow useURLParams setter to take a function as the argument (#199
Browse files Browse the repository at this point in the history
)
  • Loading branch information
maxmilton authored Jan 31, 2022
1 parent 266192c commit 7631cc6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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), '?'));
};

Expand Down

0 comments on commit 7631cc6

Please sign in to comment.