Skip to content

Commit a0f2d7b

Browse files
fix(core): label and route fields of useMenu.menuItems shouldn't be deprecated (#6353) (resolves #6352)
1 parent da9da4e commit a0f2d7b

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

.changeset/fifty-moons-flash.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
"@refinedev/core": patch
3+
---
4+
5+
fix: The `label` and `route` fields in `useMenu().menuItems` were marked as deprecated, but they are not actually deprecated. This issue was caused by `menuItems` extending from `IResourceItem`, however, `menuItems` populates these fields and handles deprecation of these fields internally. This change removes the deprecation warning for these fields.
6+
7+
```tsx
8+
export const Sider = () => {
9+
const { menuItems } = useMenu();
10+
menuItems.map((item) => {
11+
// these are safe to use
12+
console.log(item.label);
13+
console.log(item.route);
14+
item.children.map((child) => {
15+
// these are safe to use
16+
console.log(child.label);
17+
console.log(child.route);
18+
});
19+
});
20+
21+
return <div>{/* ... */}</div>;
22+
};
23+
```
24+
25+
[Fixes #6352](https://github.com/refinedev/refine/issues/6352)

packages/core/src/hooks/menu/useMenu.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ export type UseMenuProps = {
2323
hideOnMissingParameter?: boolean;
2424
};
2525

26-
export type TreeMenuItem = FlatTreeItem & {
27-
route?: string;
28-
icon?: React.ReactNode;
29-
label?: string;
30-
children: TreeMenuItem[];
31-
};
26+
export type TreeMenuItem =
27+
// Omitted because `label` and `route` are deprecated in `resource` but not in `menuItems`. These are populated in `prepareItem` for ease of use.
28+
Omit<FlatTreeItem, "label" | "route" | "children"> & {
29+
route?: string;
30+
icon?: React.ReactNode;
31+
label?: string;
32+
children: TreeMenuItem[];
33+
};
3234

3335
const getCleanPath = (pathname: string) => {
3436
return pathname
@@ -86,7 +88,9 @@ export const useMenu = (
8688

8789
const prepareItem = React.useCallback(
8890
(item: FlatTreeItem): TreeMenuItem | undefined => {
89-
if (item?.meta?.hide ?? item?.options?.hide) return undefined;
91+
if (pickNotDeprecated(item?.meta?.hide, item?.options?.hide)) {
92+
return undefined;
93+
}
9094
if (!item?.list && item.children.length === 0) return undefined;
9195

9296
const composed = item.list

0 commit comments

Comments
 (0)