Skip to content

Commit

Permalink
Added docstring.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Nov 27, 2023
1 parent 01d6261 commit 0dc8530
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/stateless/hooks/useQuerySyncedState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ export type UseQuerySyncedStateReturn<T extends unknown> = [
Dispatch<SetStateAction<T>>
]

/**
* Creates a piece of state that automatically syncs with a query parameter in
* the URL. This may be used to store a page in the URL, for example. It is
* important to ensure that the parameter is unique if this is used multiple
* times on the same page. Otherwise an infinite loop will occur as the hooks
* will bounce back and forth.
*
* @param {UseQuerySyncedStateOptions<T>} options - The options for the
* function.
* @param {T} options.param - The query parameter.
* @param {T} options.defaultValue - The state's default value.
* @return {UseQuerySyncedStateReturn<T>} - The value and its setter function,
* in the same format as `useState`.
*/
export const useQuerySyncedState = <T = string | number>({
param,
defaultValue,
Expand Down

0 comments on commit 0dc8530

Please sign in to comment.