![React Material:UI Cookbook](https://wfqqreader-1252317822.image.myqcloud.com/cover/718/36698718/b_36698718.jpg)
上QQ阅读APP看书,第一时间看更新
There's more...
Let's try setting some custom menu items and right-side buttons, using the MenuItems and RightButton properties respectively:
const ToolbarAbstraction = withStyles(styles)(
({ classes, ...props }) => (
<div className={classes.root}>
<MyToolbar
MenuItems={({ closeMenu }) => (
<Fragment>
<MenuItem onClick={closeMenu}>Page 1</MenuItem>
<MenuItem onClick={closeMenu}>Page 2</MenuItem>
<MenuItem onClick={closeMenu}>Page 3</MenuItem>
</Fragment>
)}
RightButton={() => (
<Button color="secondary" variant="contained">
Logout
</Button>
)}
{...props}
/>
</div>
)
);
Here is what the toolbar looks like when rendered:
![](https://epubservercos.yuewen.com/E00FB0/19470380001496806/epubprivate/OEBPS/Images/e36dd2f7-d322-4dc7-9e16-1f85e4ee534a.png?sign=1738904833-PHGejH4Rb7fQyZlOawILK3Eri7BQG5Lf-0-9ced426a1ab876f2761960ffa747654c)
Here is what the menu looks like with the custom menu options:
![](https://epubservercos.yuewen.com/E00FB0/19470380001496806/epubprivate/OEBPS/Images/3810a4f8-b578-4827-9db6-ec8c9ab86ff6.png?sign=1738904833-bUaPIIp4BWUI8GkrNITTtDskQKi1f7AI-0-602171524d453dff975db16057ba1e8e)
The values that you're passing to MenuItems and RightButton are functions that return React elements. These functions are actually functional components that you're creating on the fly.