|
1
|
--- |
|
2
|
sidebar_label: "Price Preferences" |
|
3
|
--- |
|
4
|
|
|
5
|
import { TypeList } from "docs-ui" |
|
6
|
|
|
7
|
export const metadata = { |
|
8
|
title: `Price Preference 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 price preference hooks retrieve price preferences from the Medusa backend. A price preference controls how prices are displayed and entered for a region or a currency, such as whether prices are tax inclusive. |
|
20
|
|
|
21
|
```tsx |
|
22
|
import { |
|
23
|
pricePreferencesQueryKeys, |
|
24
|
usePricePreferences, |
|
25
|
} from "@medusajs/dashboard/hooks" |
|
26
|
``` |
|
27
|
|
|
28
|
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). |
|
29
|
|
|
30
|
--- |
|
31
|
|
|
32
|
## usePricePreferences |
|
33
|
|
|
34
|
Retrieve a paginated list of price preferences. Pass query parameters to filter the price preferences, for example by attribute or value. |
|
35
|
|
|
36
|
```tsx |
|
37
|
const { price_preferences, count } = usePricePreferences({ |
|
38
|
limit: 20, |
|
39
|
}) |
|
40
|
``` |
|
41
|
|
|
42
|
### Parameters |
|
43
|
|
|
44
|
<TypeList |
|
45
|
types={[ |
|
46
|
{ |
|
47
|
name: "query", |
|
48
|
type: "`AdminPricePreferenceListParams`", |
|
49
|
optional: true, |
|
50
|
description: "Optional filters and pagination parameters, such as `limit`, `offset`, `attribute`, and `value`.", |
|
51
|
}, |
|
52
|
{ |
|
53
|
name: "options", |
|
54
|
type: "`object`", |
|
55
|
optional: true, |
|
56
|
description: "Optional TanStack Query options, excluding `queryKey` and `queryFn`.", |
|
57
|
}, |
|
58
|
]} |
|
59
|
/> |
|
60
|
|
|
61
|
### Returns |
|
62
|
|
|
63
|
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. |
|
64
|
|
|
65
|
<TypeList |
|
66
|
types={[ |
|
67
|
{ |
|
68
|
name: "price_preferences", |
|
69
|
type: "`AdminPricePreference[]`", |
|
70
|
description: "The list of retrieved price preferences.", |
|
71
|
}, |
|
72
|
{ |
|
73
|
name: "count", |
|
74
|
type: "`number`", |
|
75
|
description: "The total number of price preferences matching the query.", |
|
76
|
}, |
|
77
|
{ |
|
78
|
name: "limit", |
|
79
|
type: "`number`", |
|
80
|
description: "The maximum number of price preferences returned.", |
|
81
|
}, |
|
82
|
{ |
|
83
|
name: "offset", |
|
84
|
type: "`number`", |
|
85
|
description: "The number of price preferences skipped before the returned ones.", |
|
86
|
}, |
|
87
|
]} |
|
88
|
/> |
|
89
|
|
|
90
|
--- |
|
91
|
|
|
92
|
## pricePreferencesQueryKeys |
|
93
|
|
|
94
|
`pricePreferencesQueryKeys` is the query key factory for price preference queries. Use `all`, `lists()`, `list(query)`, `details()`, and `detail(id)` to build the keys that the hook above registers. |
|
95
|
|
|
96
|
Use it to invalidate cached price preference data after a custom mutation: |
|
97
|
|
|
98
|
```tsx |
|
99
|
import { useQueryClient } from "@tanstack/react-query" |
|
100
|
import { |
|
101
|
pricePreferencesQueryKeys, |
|
102
|
} from "@medusajs/dashboard/hooks" |
|
103
|
|
|
104
|
const queryClient = useQueryClient() |
|
105
|
|
|
106
|
queryClient.invalidateQueries({ |
|
107
|
queryKey: pricePreferencesQueryKeys.lists(), |
|
108
|
}) |
|
109
|
``` |