UNPKG

pro-react-use-query-hook

Version:

A simple React hook to manage URL search params (Next.js-friendly)

27 lines (26 loc) 1.14 kB
/** * A custom React hook for managing and manipulating URL query parameters in a Next.js/React.js app. * * Provides utility methods to get, set, remove, or reset query parameters in the URL, * with optional support for preserving browser history. * * Should only called inside a react function component. * * @param {boolean} [preserveHistory=false] - If `true`, changes to the URL will push a new history entry. * If `false`, changes will replace the current entry. * * @returns {{ * removeParams: (paramName: string) => void, * setParams: (paramName: string, paramValue: string) => void, * getParams: (paramName: string) => string, * removeAllParams: () => void, * poped: number | null * }} An object containing helper functions to manage query parameters and a `poped` timestamp. */ export default function useProQuery(preserveHistory?: boolean): { removeParams: (paramName: string) => void; setParams: (paramName: string, paramValue: string) => void; getParams: (paramName: string) => string; removeAllParams: () => void; poped: number | null; };