Problem
I'm trying to understand why my event handler below navItemClick isn't firing to the console when an item in the list is clicked. Also, I'm trying to figure out if it's possible to add the onClick event to the NavigationSidebarItem function to reduce repeating it on each item on the return in the NavigationSidebar component.
The component renders correctly; no errors. I also am able to see the console lines for the constructor as well as the JSX loading successfully. Just no clicky clicky message!
Code Example
class NavigationSidebar extends React.Component {
constructor(props) {
super(props);
this.navItemClick = this.navItemClick.bind(this);
console.log('NavigationSidebar:constructor => success');
}
navItemClick(event)
{
console.log('this.navItemClick: clicked');
}
render()
{
return (
<ul>
<NavigationSidebarItem description="Item1" onClick={this.navItemClick} />
<NavigationSidebarItem description="Item2" onClick={this.navItemClick} />
<NavigationSidebarItem description="Item3" onClick={this.navItemClick} />
</ul>
)
}
};
function NavigationSidebarItem(props) {
return (
<li>
<span>{props.description}</span>
</li>
);
}
ReactDOM.render(
<NavigationSidebar/>,
document.getElementById('navigation-sidebar')
);
console.log('NavigationSidebar.jsx:loaded => finished');