So, I have a tab-component that has 3 elements:
React.DOM.ul( className: 'nav navbar-nav', MenuItem( uid: 'home') MenuItem( uid: 'about') MenuItem( uid: 'contact) )
And in .render of MenuItem :
React.DOM.li( id : @props.uid, className: @activeClass, onClick: @handleClick, React.DOM.a( href: "#" +@props.uid , @props.uid) )
Each time I click on an element, the underlying router is called, which then calls the tab-component , which in turn calls the page-component .
I'm still trying to wrap my head around the fact that there is basically a one-way data stream. And I'm so used to manipulating the DOM directly.
What I want to do is add the .active class to the click, and make sure it is removed from the inactive ones.
I know a CSS trick in which you can use the data- attribute and apply different styles to the true or false attribute.
The backbone router has already received the uid variable and invokes the desired page. I just don't know how to best switch classes between tabs, because only one can be active at a time.
Now I can save some record about which tab was selected, and switch them, etc. But React.js already has this write function.
@handleClick You see, I donβt even want to use it, because the router must specify the tab-component , which should give className: '.active' And I want to avoid jQuery, because React.js does not need direct manipulation of the DOM.
I tried some things with @state, but I know for sure that there is a really elegant way to achieve this rather simple, I think I watched a presentation or videos that someone did.
I really need to get used to and change my thinking on thoughts of reactivity.
Just looking for a way to best practice, I could solve it in a very ugly and cumbersome way, but I like React.js because it is so simple.