Skip to content

Commit d92290e

Browse files
authored
doc: useSearchParams jsdoc
1 parent af7e46b commit d92290e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/routing.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,33 @@ export const useCurrentMatches = () => useRouter().matches;
193193
*/
194194
export const useParams = <T extends Params>() => useRouter().params as T;
195195

196+
/**
197+
* Retrieves a tuple containing a reactive object to read the current location's query parameters and a method to update them.
198+
* The object is a proxy so you must access properties to subscribe to reactive updates.
199+
* **Note** that values will be strings and property names will retain their casing.
200+
*
201+
* The setter method accepts an object whose entries will be merged into the current query string.
202+
* Values `''`, `undefined` and `null` will remove the key from the resulting query string.
203+
* Updates will behave just like a navigation and the setter accepts the same optional second parameter as `navigate` and auto-scrolling is disabled by default.
204+
*
205+
* @examples
206+
* ```js
207+
* const [searchParams, setSearchParams] = useSearchParams();
208+
*
209+
* return (
210+
* <div>
211+
* <span>Page: {searchParams.page}</span>
212+
* <button
213+
* onClick={() =>
214+
* setSearchParams({ page: (parseInt(searchParams.page) || 0) + 1 })
215+
* }
216+
* >
217+
* Next Page
218+
* </button>
219+
* </div>
220+
* );
221+
* ```
222+
*/
196223
export const useSearchParams = <T extends SearchParams>(): [
197224
Partial<T>,
198225
(params: SetSearchParams, options?: Partial<NavigateOptions>) => void

0 commit comments

Comments
 (0)