I'm trying to bind the data to the MenuItems at the nested menu level. I can successfully map the data to populate the main levels, but the submenus are giving me an error.
My JSON looks like this:
const languages = [
{
name: 'English',
icon: './assets/images/flags/uk.png',
link: ''
},
{
name: 'Español',
icon: './assets/images/flags/Spain.png',
link: ''
},
{
name: 'Français',
icon: './assets/images/flags/France.png',
link: ''
}
];
I am saving the submenu in a const so I can use it in the render. (I believe this is my problem area but not sure what I need to do)
class Menu extends React.Component {
constructor(props) {
super(props);
this.state = {
show: false,
open: false
}
}
render() {
const { colorOption } = this.props;
//the code inside this const will work if I insert it inside my IconMenu. But it doesn't work inside the menuItems property which should be able to hold MenuItem objects
const languageMenu = {languages.map((item, index) => (
<MenuItem
key={index}
className={classnames('menu-item', {
'bg-color-medlight': ['11', '12', '13', '14', '15', '16'].indexOf(colorOption) >= 0,
'bg-color-meddark': ['21', '22', '23', '24', '25', '26'].indexOf(colorOption) >= 0
})}
primaryText={languages[index].name}
style={{userMenuItem}}
leftIcon={
<img className="flag" src={languages[index].icon}/>
}/>
))}
return(
<div style={{zIndex:2}}>
<ul className="list-unstyled">
<li>
<IconMenu
className="user"
iconButtonElement={
<RaisedButton style={ImgIconButtonStyle}><PersonalMenuIcon/></RaisedButton>
}
onChange={this.handleChange}
anchorOrigin={{horizontal: 'right', vertical: 'bottom'}}
targetOrigin={{horizontal: 'right', vertical: 'top'}}>
<MenuItem
className={classnames('menu-item', {
'bg-color-medlight': ['11', '12', '13', '14', '15', '16'].indexOf(colorOption) >= 0,
'bg-color-meddark': ['21', '22', '23', '24', '25', '26'].indexOf(colorOption) >= 0
})}
primaryText="English"
rightIcon={<ArrowDropRight />}
style={{userMenuItem}}
leftIcon={
<img className="flag" src="./assets/images/flags/uk.png"/>
}
menuItems={{languageMenu}}
/>
</IconMenu>
</li>
</ul>
</div>
);
}
}
In a perfect world, a regular nested menu looks like this:
import React from 'react';
import IconMenu from 'material-ui/IconMenu';
import MenuItem from 'material-ui/MenuItem';
import IconButton from 'material-ui/IconButton';
import Divider from 'material-ui/Divider';
import Download from 'material-ui/svg-icons/file/file-download';
import ArrowDropRight from 'material-ui/svg-icons/navigation-arrow-drop-right';
import MoreVertIcon from 'material-ui/svg-icons/navigation/more-vert';
/**
* Example of nested menus within an IconMenu.
*/
const IconMenuExampleNested = () => (
<IconMenu
iconButtonElement={<IconButton><MoreVertIcon /></IconButton>}
anchorOrigin={{horizontal: 'left', vertical: 'top'}}
targetOrigin={{horizontal: 'left', vertical: 'top'}}
>
<MenuItem
primaryText="Copy & Paste"
rightIcon={<ArrowDropRight />}
menuItems={[
<MenuItem primaryText="Cut" />,
<MenuItem primaryText="Copy" />,
<Divider />,
<MenuItem primaryText="Paste" />,
]}
/>
<MenuItem
primaryText="Case Tools"
rightIcon={<ArrowDropRight />}
menuItems={[
<MenuItem primaryText="UPPERCASE" />,
<MenuItem primaryText="lowercase" />,
<MenuItem primaryText="CamelCase" />,
<MenuItem primaryText="Propercase" />,
]}
/>
</IconMenu>
);
export default IconMenuExampleNested;
And the error I am getting is
Module build failed: SyntaxError: C:/xampp/htdocs/ScalaCMReact/src/components/Header/UserMenu.js: Unexpected token, expected , (109:33)
107 | const { colorOption } = this.props;
108 |
109 | const languageMenu = {languages.map((item, index) => (
| ^
110 | <MenuItem
111 | key={index}
112 | className={classnames('menu-item', {
@ ./src/components/Header/index.js 23:16-37
@ ./src/routes/app/components/MainApp.js
@ ./src/routes/app/index.js
@ ./src/client.js
@ multi (webpack)-dev-server/client?http://localhost:8000 webpack/hot/dev-server webpack-dev-server/client?http://0.0.0.0:8000/ webpack/hot/only-dev-server react-hot-loader/patch ./client.js
What am I doing wrong?
Thanks in advance