Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCezary Burzykowski
18,291 PointsReact: onClick on Anchor element doesn't seem to work
I'm learning React for some time now and I have encountered a strange problem that I have troubles solving. It's pretty simple: onClick on my Anchor element doesn't seem to work.
Here is my code:
var Tabs = React.createClass ({
propTypes: {
onTabClick: React.PropTypes.func.isRequired,
tabName: React.PropTypes.string.isRequired,
},
render: function() {
return (
<li className="nav-item">
<a id="user-list-tab" className="nav-link tab-link" href="#" onClick={event => this.props.onTabClick(event)}>{this.props.tabName}</a>
</li>
);
}
})
var TabsNav = React.createClass ({
getInitialState: function() {
return {
tabs: [
{name: "Users list", isActive: false, key: 1},
{name: "Create new user", isActive: false, key: 2},
],
}
},
showTabContent: function(event) {
console.log("it works");
event.preventDefault();
},
render: function() {
return (
<ul className="nav nav-tabs justify-content-center">
{this.state.tabs.map(function(element, index) {
return <Tabs tabName={element.name} className={element.isActive ? "nav-item active" : "nav-item"} onTabClick={this.showTabContent} key={element.key} />
}.bind(this))}
</ul>
);
}
})
When I click on the link nothing seems to happen ....
I have no error in my console, it just seem that it doesn't work because it does not log "it works" on the onClick....
I would really appreciate any help