Skip to content

Commit

Permalink
chore: improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadshaheer authored and YounixM committed Oct 28, 2024
1 parent e88e24e commit c206f4f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions frontend/src/hooks/useUrlQueryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ const useUrlQueryData = <T>(
(newQueryData: T): void => {
const newQuery = JSON.stringify(newQueryData);

// Create a new URLSearchParams to get the latest URL state
// Create a new URLSearchParams object with the current URL's search params
// This ensures we're working with the most up-to-date URL state
const currentUrlQuery = new URLSearchParams(window.location.search);

// Update the query parameter
// Update or add the specified query parameter with the new serialized data
currentUrlQuery.set(queryKey, newQuery);

// Generate the new URL with updated parameters
// Construct the new URL by combining the current pathname with the updated query string
const generatedUrl = `${location.pathname}?${currentUrlQuery.toString()}`;

history.replace(generatedUrl);
},
[history, location.pathname, queryKey],
Expand Down

0 comments on commit c206f4f

Please sign in to comment.