Im trying to dynamically print a lot of components into a li list.
In the parent component, the list menuLinks is an array. Each child of menuLinks is a component (LinkToChangePassword is a react functional component):
export default class Header extends Component{
constructor(props){
super( props );
}
render(){
const menuLinks = [
LinkToChangePassword,
LinkToResetPassword,
LinkToChangeEmail,
LinkToLogOut
];
return(
<div className="header">
<LinkToHome classAttr=""/>
<h1 className="">{ this.props.heading }</h1>
<DropDownMenu links = { menuLinks }/>
</div>
);
}
}
In my child component, I'd like to attach these components:
export default class DropDownMenu extends Component{
constructor( props ){
super( props );
}
render(){
let renderMenuItems = this.props.links.map(
( item, i ) => <li className = "menuItem"
key = {`li${i}`}>
{item}
</li>
);
return <ul className = "profileMenu">
{ renderMenuItems }
</ul>;
}
}
However, this doesnt work & I get empty list.