I'm in the process of translating a 90% complete website produced in HTML, CSS and jQuery into a more forward thinking react "application". I have some pretty basic principals that I'm struggling to get to grips with - I really like react's JSX language but and struggling to deal with heavy UI manipulation that I've achieve in jQuery previously.
To get me used to the concepts I'm starting with one of the most simple interactions on my website - Hover over the menu button and bring out the side menu partially (e.g. 20px). My components are structured like so:
var App = React.createClass({
render: function() {
return (
<div id="reactWrap">
<MainNav ref="main-nav"/>
<SideNav projects={PROJECTS} ref="side-nav" />
<RouteHandler projects={PROJECTS} ref="content" />
</div>
)
}
});
MainNav includes the 'hamburger' button and the site title:
render: function() {
return (
<nav className="fixed-nav">
<div id="menu-button" onMouseEnter={this.teaseMenu} onMouseLeave={this.unteaseMenu} ref="menu-btn">
<span className="menu-line"></span>
</div>
<span className="site-title">Lorem Ipsum</span>
</nav>
)
}
When "#menu-button" is hovered over I'm changing the state tree that I have defined in Baobab inside "teaseMenu()" using "menuActions.isHovering()".
....
teaseMenu: function(e) {
menuActions.isHovering();
// other stuff done
},....
What I'm struggling with is that once the change has been affected in my stateTree, I'm unsure how to then give the knowledge of this change to all of the other elements that rely on it. For example, how does the SideNav which is totally unrelated to "MainNav" and it's child "#menu-button" become aware of this change and alter it's state accordingly? This would simply be solved in jQuery with something like the following:
globalVars.menuBtn.on({
mouseenter: function(e) {
var self = $(this);
var movePercentage = (-100 + (20 / globalVars.sideNavW * 100))/2;
if (!pageStatus.menuActive) {
globalVars.wrap.addClass('menu-hover');
globalVars.sideNav.css({
'left': movePercentage + '%'
});
menuBtnIn(e, self);
}
},....