无法在 react-admin 中自定义用户菜单
Can't customise user menu in react-admin
我正在尝试自定义 react-admin
中的用户菜单,并且我已按照 react-admin
存储库中的说明和示例进行操作,但我仍然收到此错误:
Type '{ ref: ForwardedRef<any>; to: string; primaryText: string; leftIcon: Element; onClick: any; sidebarIsOpen: true; }' is missing the following properties from type 'Pick<any, "selected" | "dense" | "className" | "style" | "classes" | "innerRef" | "button" | "slot" | "title" | "key" | "value" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | ... 277 more ... | "ContainerProps">': selected, dense, className, style, and 283 more. TS2740
这是我的代码。
import SettingsIcon from '@material-ui/icons/Settings';
import { forwardRef } from 'react';
const ConfigurationMenu = forwardRef<any, any>((props, ref) => (
<MenuItemLink
ref={ref}
to="/metamaskLogin"
primaryText="MetaMask"
leftIcon={<SettingsIcon />}
// onClick={onClick} // close the menu on click
// dense={true}
onClick={props.onClick}
sidebarIsOpen
/>
));
const MyUserMenu = (props: any) => (
<UserMenu {...props}>
<ConfigurationMenu />
</UserMenu>
);
export const MyAppBar = (props: any) => <AppBar {...props} userMenu={<MyUserMenu />} />;
我测试过设置userMenu={false}
可以隐藏用户菜单
示例代码可以在这里找到:https://github.com/marmelab/react-admin/blob/master/examples/demo/src/layout/AppBar.tsx
想通了,只需要将 {...props}
添加到 MenuItemLink
我正在尝试自定义 react-admin
中的用户菜单,并且我已按照 react-admin
存储库中的说明和示例进行操作,但我仍然收到此错误:
Type '{ ref: ForwardedRef<any>; to: string; primaryText: string; leftIcon: Element; onClick: any; sidebarIsOpen: true; }' is missing the following properties from type 'Pick<any, "selected" | "dense" | "className" | "style" | "classes" | "innerRef" | "button" | "slot" | "title" | "key" | "value" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | ... 277 more ... | "ContainerProps">': selected, dense, className, style, and 283 more. TS2740
这是我的代码。
import SettingsIcon from '@material-ui/icons/Settings';
import { forwardRef } from 'react';
const ConfigurationMenu = forwardRef<any, any>((props, ref) => (
<MenuItemLink
ref={ref}
to="/metamaskLogin"
primaryText="MetaMask"
leftIcon={<SettingsIcon />}
// onClick={onClick} // close the menu on click
// dense={true}
onClick={props.onClick}
sidebarIsOpen
/>
));
const MyUserMenu = (props: any) => (
<UserMenu {...props}>
<ConfigurationMenu />
</UserMenu>
);
export const MyAppBar = (props: any) => <AppBar {...props} userMenu={<MyUserMenu />} />;
我测试过设置userMenu={false}
示例代码可以在这里找到:https://github.com/marmelab/react-admin/blob/master/examples/demo/src/layout/AppBar.tsx
想通了,只需要将 {...props}
添加到 MenuItemLink