I have a menu in my AppBar and I'd like to have to have certain items show up as buttons on the AppBar when there's space and as menu items in an existing menu when there isn't. That is, the menu is always present and always has items in it. I'd just like some functions to be AppBar buttons or menu items depending on the screen size.
Here's a simplified example:
<Menu
id="settings-menu"
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={handleClose}
>
<Hidden lgUp>
<MenuItem onClick={logout}>
<ListItemIcon><ExitToAppIcon /></ListItemIcon>
<ListItemText primary="Hidden log out" />
</MenuItem>
</Hidden>
<MenuItem onClick={logout}>
<ListItemIcon><ExitToAppIcon /></ListItemIcon>
<ListItemText primary="Log out" />
</MenuItem>
</Menu>
When I open the menu, I get an error message in the console:
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
Check the render method of `ForwardRef(Menu)`.
in Hidden (at NavBar.js:76)
in ul (created by ForwardRef(List))
in ForwardRef(List) (created by WithStyles(ForwardRef(List)))
in WithStyles(ForwardRef(List)) (created by ForwardRef(MenuList))
in ForwardRef(MenuList) (created by ForwardRef(Menu))
in div (created by ForwardRef(Paper))
in ForwardRef(Paper) (created by WithStyles(ForwardRef(Paper)))
in WithStyles(ForwardRef(Paper)) (created by Transition)
in Transition (created by ForwardRef(Grow))
in ForwardRef(Grow) (created by TrapFocus)
in TrapFocus (created by ForwardRef(Modal))
in div (created by ForwardRef(Modal))
in ForwardRef(Portal) (created by ForwardRef(Modal))
in ForwardRef(Modal) (created by ForwardRef(Popover))
in ForwardRef(Popover) (created by WithStyles(ForwardRef(Popover)))
in WithStyles(ForwardRef(Popover)) (created by ForwardRef(Menu))
in ForwardRef(Menu) (created by WithStyles(ForwardRef(Menu)))
in WithStyles(ForwardRef(Menu)) (at NavBar.js:70)
in div (at NavBar.js:50)
in div (created by ForwardRef(Toolbar))
in ForwardRef(Toolbar) (created by WithStyles(ForwardRef(Toolbar)))
in WithStyles(ForwardRef(Toolbar)) (at NavBar.js:48)
in header (created by ForwardRef(Paper))
in ForwardRef(Paper) (created by WithStyles(ForwardRef(Paper)))
in WithStyles(ForwardRef(Paper)) (created by ForwardRef(AppBar))
in ForwardRef(AppBar) (created by WithStyles(ForwardRef(AppBar)))
in WithStyles(ForwardRef(AppBar)) (at NavBar.js:47)
in Header (at Layout.js:32)
in div (at Layout.js:31)
in div (at Layout.js:29)
in Layout (at App.js:18)
in Unknown (at src/index.js:39)
in Router (at src/index.js:38)
in ThemeProvider (at src/index.js:37)
in Provider (at src/index.js:36)
Are <Hidden>
components allowed within a <Menu>
? If not, what's a good way to allow menu items to appear conditionally based on the screen size?