useParsed
useParsed
is a hook that leverages the parse
method of the routerProvider
to access the URL and query parameters along with the inferred resource
, action
and id
from the URL.
Usageβ
import { useParsed } from "@refinedev/core";
type MyParams = {
someParam: string;
};
const MyComponent = () => {
const {
resource,
action,
id,
pathname,
params: {
filters,
sorters,
current,
pageSize,
...restParams // TParams - Any other parameters are also parsed and available in `params`
},
} = useParsed<MyParams>();
/* ... */
};
Return Valuesβ
resourceβ
This is the active resource that is matched by the current route and the action definitions in the resources
array of the Refine
component. It will be undefined
if there is no match.
actionβ
This is the active action that is matched by the current route and the action definitions in the resources
array of the Refine
component. It will be undefined
if there is no match.
idβ
This is the main parameter used by the Refine in API interactions. It will also be available in the params
object but it is also available as a separate value for convenience. It will be undefined
if there is no id
parameter in the URL.
pathnameβ
This is the current pathname of the URL.
params.filtersβ
This is the filters that are parsed from the URL. It will be undefined
if there is no filters
parameter in the URL. This property is used in the syncWithLocation
feature of the useTable
.
params.sortersβ
This is the sorters that are parsed from the URL. It will be undefined
if there is no sorters
parameter in the URL. This property is used in the syncWithLocation
feature of the useTable
.
params.currentβ
This is the current page that is parsed from the URL. It will be undefined
if there is no current
parameter in the URL. This property is used in the syncWithLocation
feature of the useTable
.
params.pageSizeβ
This is the page size that is parsed from the URL. It will be undefined
if there is no pageSize
parameter in the URL. This property is used in the syncWithLocation
feature of the useTable
.
paramsβ
This is the object that contains all the parameters that are parsed from the URL. It will be an empty object if there is no parameter in the URL. params
object contains both the URL parameters and the query parameters.