documentation/versioned_docs/version-4.xx.xx/routing/hooks/use-resource-params/index.md
useResourceParams is used to get the related parameters of the current resource such as resource, id and action. It also provides formAction to determine the action of the form and setId to set the id programmatically without having to use a separate state for it.
const {
id?, // ID of the record
setId, // Function to set the ID
resource?, // Resource object
action?, // Passed action or inferred from the route
identifier?, // Identifier value of the resource
formAction?, // Form action derived from the action
} = useResourceParams({
id?, // ID to set explicitly. Inferred from the route if not provided
action?, // Action to set explicitly. Inferred from the route if not provided
resource?, // Resource object to set explicitly. Inferred from the route if not provided
});
id from the routeWhen the id is not explicitly passed, it can be inferred from the route. Inference from the route is only possible under certain conditions:
resource value.resource value and it's the same as the current route.This check is necessary to prevent the id from being inferred from a different resource.
If there's no explicit id value, no id from the route or there's a mismatch between the resource and the route, the id will be set to undefined.
formAction from the routeThe formAction is inferred from the action value.
action is a valid form action (create, edit or clone), the formAction will be set to the action.formAction will be set to create.This is done to provide a more convenient way to determine the action of the form.
The resource object.
Identifier value for the current resource, this can either be the identifier property or the name property of the resource.
id parameter to be used in the actions.
Function to set the id programmatically.
Current action to be performed. This can be explicitly passed via the action parameter or inferred from the route.
Apart from the action value, formAction can only be create, edit or clone. If the action is not one of these, formAction will be set to create for convenience.
| Description | Type |
|---|---|
| resource | IResourceItem | undefined |
| identifier | string | undefined |
| id | BaseKey | undefined |
| setId | (id: BaseKey) => void |
| action | undefined | "list" | "create" | "edit" | "show" | "clone" |
| formAction | "create" | "edit" | "clone" |