diff --git a/projects/packages/videopress/changelog/update-video-minot-ty-enhancements-in-use-search-params-hook b/projects/packages/videopress/changelog/update-video-minot-ty-enhancements-in-use-search-params-hook new file mode 100644 index 0000000000000..8baaa566c32c2 --- /dev/null +++ b/projects/packages/videopress/changelog/update-video-minot-ty-enhancements-in-use-search-params-hook @@ -0,0 +1,4 @@ +Significance: patch +Type: added + +VideoPress: minor TS enhancement in the useSearchParams() hook diff --git a/projects/packages/videopress/src/client/admin/hooks/use-search-params/index.ts b/projects/packages/videopress/src/client/admin/hooks/use-search-params/index.ts index 4eee99b1d419b..5b5518ddbf293 100644 --- a/projects/packages/videopress/src/client/admin/hooks/use-search-params/index.ts +++ b/projects/packages/videopress/src/client/admin/hooks/use-search-params/index.ts @@ -3,6 +3,8 @@ */ import { useLocation, useHistory } from 'react-router-dom'; +type SearchParamNameProp = 'page' | 'q'; + export const useSearchParams = () => { const location = useLocation(); const history = useHistory(); @@ -11,21 +13,21 @@ export const useSearchParams = () => { /** * Gets a given parameter from the search query. * - * @param {string} parameterName - The name of the parameter to get from the query string. - * @param {string} defaultValue - The default value to return if the given parameter is not set on the query string. - * @returns {string} - The value of the parameter if it's set. The defaultValue if the parameter is not set. + * @param {SearchParamNameProp} parameterName - The name of the parameter to get from the query string. + * @param {string} defaultValue - The default value to return if the given parameter is not set on the query string. + * @returns {string|null} The value of the parameter if it's set. The defaultValue if the parameter is not set. */ - const getParam = ( parameterName: string, defaultValue: string = null ) => { + const getParam = ( parameterName: SearchParamNameProp, defaultValue: string = null ): string => { return searchParams.has( parameterName ) ? searchParams.get( parameterName ) : defaultValue; }; /** * Sets a given parameter on the search query data, but does not refresh the URL. * - * @param {string} parameterName - The name of the parameter to set on the query string. - * @param {string} value - The value to be set for the parameter on the query string. + * @param {SearchParamNameProp} parameterName - The name of the parameter to set on the query string. + * @param {string} value - The value to be set for the parameter on the query string. */ - const setParam = ( parameterName: string, value: string = null ) => { + const setParam = ( parameterName: SearchParamNameProp, value: string = null ) => { searchParams.set( parameterName, value ); }; @@ -33,9 +35,9 @@ export const useSearchParams = () => { * Deletes a given parameter from the search query data, which results on removing * it from the URL when it gets updated. * - * @param {string} parameterName - The name of the parameter to delete. + * @param {SearchParamNameProp} parameterName - The name of the parameter to delete. */ - const deleteParam = ( parameterName: string ) => { + const deleteParam = ( parameterName: SearchParamNameProp ) => { searchParams.delete( parameterName ); };