|
1
|
--- |
|
2
|
sidebar_label: "Users" |
|
3
|
--- |
|
4
|
|
|
5
|
import { TypeList } from "docs-ui" |
|
6
|
|
|
7
|
export const metadata = { |
|
8
|
title: `User Hooks - Admin Components`, |
|
9
|
} |
|
10
|
|
|
11
|
# {metadata.title} |
|
12
|
|
|
13
|
<Note> |
|
14
|
|
|
15
|
These hooks are available since Medusa [v2.21.0](https://github.com/medusajs/medusa/releases/tag/v2.21.0). |
|
16
|
|
|
17
|
</Note> |
|
18
|
|
|
19
|
The user hooks retrieve admin users from the Medusa backend, such as the user that created an order edit or the user assigned to a task. |
|
20
|
|
|
21
|
```tsx |
|
22
|
import { useUser } from "@medusajs/dashboard/hooks" |
|
23
|
``` |
|
24
|
|
|
25
|
These hooks are built on [TanStack Query](https://tanstack.com/query/latest). Use them in your [widgets](!docs!/learn/fundamentals/admin/widgets) and [UI routes](!docs!/learn/fundamentals/admin/ui-routes). |
|
26
|
|
|
27
|
--- |
|
28
|
|
|
29
|
## useUser |
|
30
|
|
|
31
|
Retrieve a single admin user by its ID. Pass a query object as the second parameter to select the fields and relations to retrieve. |
|
32
|
|
|
33
|
```tsx |
|
34
|
const { user, isPending } = useUser("user_123") |
|
35
|
``` |
|
36
|
|
|
37
|
### Parameters |
|
38
|
|
|
39
|
<TypeList |
|
40
|
types={[ |
|
41
|
{ |
|
42
|
name: "id", |
|
43
|
type: "`string`", |
|
44
|
optional: false, |
|
45
|
description: "The user's ID.", |
|
46
|
}, |
|
47
|
{ |
|
48
|
name: "query", |
|
49
|
type: "`AdminUserParams`", |
|
50
|
optional: true, |
|
51
|
description: "Optional selection parameters, such as `fields`.", |
|
52
|
}, |
|
53
|
{ |
|
54
|
name: "options", |
|
55
|
type: "`object`", |
|
56
|
optional: true, |
|
57
|
description: "Optional TanStack Query options, excluding `queryKey` and `queryFn`.", |
|
58
|
}, |
|
59
|
]} |
|
60
|
/> |
|
61
|
|
|
62
|
<Note> |
|
63
|
|
|
64
|
This hook retrieves the user with the specified ID, not the currently authenticated user. |
|
65
|
|
|
66
|
</Note> |
|
67
|
|
|
68
|
### Returns |
|
69
|
|
|
70
|
Along with the following, the hook returns the rest of TanStack Query's [`useQuery`](https://tanstack.com/query/latest/docs/framework/react/reference/useQuery) result. |
|
71
|
|
|
72
|
<TypeList |
|
73
|
types={[ |
|
74
|
{ |
|
75
|
name: "user", |
|
76
|
type: "`AdminUser`", |
|
77
|
description: "The retrieved user. It's `undefined` until the request resolves.", |
|
78
|
}, |
|
79
|
]} |
|
80
|
/> |