I’m a bit confused. I’m adding a simple alert function to an onClick event through a map inside my component.
But the actual resulting html has no onclick events tied to the list item. This doesn’t seem to be rocket science, what gives here?
import React from 'react';
import CreateHub from '../containers/sidebar_hubs-createhub.js';
const renderIfData = ( hubs ) => {
if ( hubs && hubs.length > 0 ) {
return hubs.map( ( hub ) => {
return <li key={ hub._id } onClick={ ()=>{ alert('KITTENS RULE') }} >{ hub.name }</li>;
});
} else {
return <p>No hubs yet!</p>;
}
};
const SidebarHubs = ({hubs}) => (
<div>
<h1> Hubs </h1>
<ul> { renderIfData( hubs) } </ul>
<CreateHub />
</div>
);
export default SidebarHubs;