Skip to content

Commit 75f547f

Browse files
authored
Merge pull request #10356 from marmelab/doc-appbar-usermenu
[Doc] Fix `<AppBar userMenu>` example usage
2 parents a733c6c + 7c88d4e commit 75f547f

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

docs/AppBar.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,26 @@ The content of the user menu depends on the return value of `authProvider.getIde
248248

249249
You can customize the user menu by passing a `userMenu` prop to the `<AppBar>` component.
250250

251-
```jsx
251+
```tsx
252252
import * as React from 'react';
253-
import { AppBar, UserMenu, useUserMenu } from 'react-admin';
253+
import { AppBar, Logout, UserMenu, useUserMenu } from 'react-admin';
254254
import { MenuItem, ListItemIcon, ListItemText } from '@mui/material';
255255
import SettingsIcon from '@mui/icons-material/Settings';
256+
import { Link } from "react-router-dom";
256257

257258
// It's important to pass the ref to allow Material UI to manage the keyboard navigation
258-
const SettingsMenuItem = React.forwardRef((props, ref) => {
259-
// We are not using MenuItemLink so we retrieve the onClose function from the UserContext
260-
const { onClose } = useUserMenu();
259+
const SettingsMenuItem = React.forwardRef<HTMLAnchorElement>((props, ref) => {
260+
const userMenuContext = useUserMenu();
261+
if (!userMenuContext) {
262+
throw new Error("<SettingsMenuItem> should be used inside a <UserMenu>");
263+
}
264+
const { onClose } = userMenuContext;
261265
return (
262266
<MenuItem
263267
onClick={onClose}
264268
ref={ref}
269+
component={Link}
270+
to="/settings"
265271
// It's important to pass the props to allow Material UI to manage the keyboard navigation
266272
{...props}
267273
>
@@ -273,7 +279,7 @@ const SettingsMenuItem = React.forwardRef((props, ref) => {
273279
);
274280
});
275281

276-
const MyAppBar = () => (
282+
export const MyAppBar = () => (
277283
<AppBar
278284
userMenu={
279285
<UserMenu>

0 commit comments

Comments
 (0)