How to create a new page with React js - reactjs

I have a code where this would essentially show links that you can press and would redirect you. I am have a problem where I am trying to click the link to "eco-news" and essentially open up a page with news articles in it. I have coded the news section, but I just dont know how to implement it.
Home > News > (directed to a new page where news would would populate)
import React from "react";
import './sidebar.css';
//import News from "../news section/News";
import { Link } from 'react-router-dom'
// Imported Images ==============>
import logo from '../../Assets/logo.png';
// Imported icons ===============>
import {IoMdSpeedometer} from 'react-icons/io';
import {TfiWorld} from 'react-icons/tfi';
import {BsQuestionCircle} from 'react-icons/bs'
// placeholder logo image
const Sidebar = () => {
return (
<div className="sideBar grid">
<div className="logoDiv flex">
<img src={logo} alt="World Space Logo" />
<h2>World Space.</h2>
</div>
<div className="menuDiv">
<h3 className="divTitle">
CONSUMPTION OVERVIEW
</h3>
<ul className="menuLists grid">
<li className="listItem">
<a href="/#" className="menuLink flex">
<IoMdSpeedometer className="icon" />
<span className="smallText">
Readout
</span>
</a>
</li>
<li className="listItem">
<a href="/#" className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Driven Equivalent
</span>
</a>
</li>
<li className="listItem">
<a href="/#" className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Efficiency Score
</span>
</a>
</li>
</ul>
</div>
{/* This is the tab for the Eco news, please update the necessary fonts and spacing */}
<div className="menuDiv">
<h3 className="divTitle">
NEWS
</h3>
<ul className="menuLists grid">
<li className="listItem">
{/* <a href=/News className="menuLink flex"> */}
<Link to ='\News' className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Eco-News
</span>
</Link>
{/* </a> */}
</li>
</ul>
</div>
<div className="settingsDiv">
<h3 className="divTitle">
SETTINGS
</h3>
<ul className="menuLists grid">
<li className="listItem">
<a href="/#" className="menuLink flex">
<IoMdSpeedometer className="icon" />
<span className="smallText">
Dashboard
</span>
</a>
</li>
<li className="listItem">
<a href="/#" className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Consumption Overview
</span>
</a>
</li>
<li className="listItem">
<a href="/#" className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Goals
</span>
</a>
</li>
<li className="listItem">
<a href="/#" className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Achievements
</span>
</a>
</li>
</ul>
</div>
<div className="sideBarCard">
<BsQuestionCircle className="icon" />
<div className="cardContent">
<h3>Help Center</h3>
{/*<p>Having trouble in World Space, please contact us.</p>
<button className="btn">Go to help center</button>*/}
</div>
</div>
</div>
);
}
export default Sidebar;
<div className="menuDiv">
<h3 className="divTitle">
NEWS
</h3>
<ul className="menuLists grid">
<li className="listItem">
{/* <a href=/News className="menuLink flex"> */}
<Link to ='\News' className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Eco-News
</span>
</Link>
{/* </a> */}
</li>
</ul>
</div>
if you click the link it would lead to a broken page.
What it looks like so far

Ensure that you have followed the below steps as pre requisites
Create browser router
Add a route for your News component
Only then will your routing work

Related

React Dom Outlet Route Confusion. Nest 3 Part Page Into one Route. React Router v6

I'm having a hard time understanding how the routes and outlets work in react. My problem is this.
If I have a route that should load 3 parts.
-Top Menu
-Side Menu
-Center Content
But the center content is contained in the div thats wrapped by the "Side Menu" how do I wrap another element that will be changing inside of a previous component. My goal is to use the first 2 in all of the routes and based on the route the center content will change.
This is what it should look like
<div id="layoutSideNav">
<div id="layoutsidenav_nav"></div>
<div id="layoutSidenav_content"></div>
</div>
But for some reason all I can get is this
<div id="layoutSideNav">
<div id="layoutsidenav_nav"></div>
</div>
<div id="layoutSidenav_content"></div>
My react looks like this.
3 Components
Contains the top nav
contains the side nav
contains body elements that will change.
App()
<Route
path='/admin-dashboard'
element={
<>
<AdminNavigation />
<AdminNavigationLeft />
<AdminDashBoardHome />
</>
}
>
If I add <Outlet/> before the closing div in "layoutSideNav" component. nothing happens. If I remove the outlets from all components the app() looks the same. The top nav and side nave display correclty, but the center content is wonky.
I feel like routes is so much more abstract than I'm used to so maybe I'm just not thinking about it logically. Thank you so much for your help!
I tried using <Outlet/> to adjust how where the third component content displayed.
I've added my full code below for review.
const AdminNavigation = () =>{
const toggleSideMenu = event => {
// 👇️ toggle class on click
document.getElementsByTagName('body')[0].classList.toggle('sb-sidenav-toggled');
};
return (
<Fragment>
<nav className="sb-topnav navbar navbar-expand navbar-dark bg-dark">
<a className="navbar-brand ps-3" href="index.html">Woodmoore Improvement</a>
<button className="btn btn-link btn-sm order-1 order-lg-0 me-4 me-lg-0" onClick={toggleSideMenu} id="sidebarToggle" href="#!"><i className="fas fa-bars"></i></button>
<form className="d-none d-md-inline-block form-inline ms-auto me-0 me-md-3 my-2 my-md-0">
<div className="input-group">
<input className="form-control" type="text" placeholder="Search for..." aria-label="Search for..." aria-describedby="btnNavbarSearch" />
<button className="btn btn-primary" id="btnNavbarSearch" type="button"><i className="fas fa-search"></i></button>
</div>
</form>
<ul className="navbar-nav ms-auto ms-md-0 me-3 me-lg-4">
<li className="nav-item dropdown">
<a className="nav-link dropdown-toggle" id="navbarDropdown" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false"><i className="fas fa-user fa-fw"></i></a>
<ul className="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<li><a className="dropdown-item" href="#!">Settings</a></li>
<li><hr className="dropdown-divider" /></li>
<li><a className="dropdown-item" href="#!">Logout</a></li>
</ul>
</li>
</ul>
</nav>
</Fragment>
)
}
export default AdminNavigation;
const AdminDashBoardHome = () => {
return(
<Fragment>
<div id='layoutSidenav_content'>
<main>
<div className='container-fluid px-4'>
<h1 className='mt-4'>HOA Member Manager</h1>
<ol className='breadcrumb mb-4'>
<li className='breadcrumb-item active'>Member Map</li>
</ol>
<div className='row'>
<div className='col-lg-12'>
<div className='embed-responsive embed-responsive-16by9'>
<div id='map_canvas' className='embed-responsive-item pb-4' >
</div>
</div>
</div>
</div>
<div className='row'>
</div>
<div className='card mb-4'>
<div className='card-header'>
<i className='fas fa-table me-1'></i>
Member Lookup
</div>
<MemberDataList/>
</div>
</div>
</main>
<footer className='py-4 bg-light mt-auto'>
<div className='container-fluid px-4'>
<div className='d-flex align-items-center justify-content-between small'>
<div className='text-muted'>Copyright © Your Website 2022</div>
<div>
<a href='#'>Privacy Policy</a>
·
<a href='#'>Terms & Conditions</a>
</div>
</div>
</div>
</footer>
</div>
</Fragment>
)
}
export default AdminDashBoardHome;
const AdminNavigationLeft = () => {
document.body.classList.add('sb-nav-fixed');
return(
<Fragment>
<div id="layoutSidenav">
<Outlet/>
<div id="layoutSidenav_nav">
<nav className="sb-sidenav accordion sb-sidenav-dark" id="sidenavAccordion">
<div className="sb-sidenav-menu">
<div className="nav">
<div className="sb-sidenav-menu-heading">Core</div>
<a className="nav-link" href="index.html">
<div className="sb-nav-link-icon"><i className="fas fa-tachometer-alt"></i></div>
Dashboard
</a>
<div className="sb-sidenav-menu-heading">Interface</div>
<a className="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#collapseLayouts" aria-expanded="false" aria-controls="collapseLayouts">
<div className="sb-nav-link-icon"><i className="fas fa-columns"></i></div>
Layouts
<div className="sb-sidenav-collapse-arrow"><i className="fas fa-angle-down"></i></div>
</a>
<div className="collapse" id="collapseLayouts" aria-labelledby="headingOne" data-bs-parent="#sidenavAccordion">
<nav className="sb-sidenav-menu-nested nav">
<a className="nav-link" href="layout-static.html">Static Navigation</a>
<a className="nav-link" href="layout-sidenav-light.html">Light Sidenav</a>
</nav>
</div>
<a className="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#collapsePages" aria-expanded="false" aria-controls="collapsePages">
<div className="sb-nav-link-icon"><i className="fas fa-book-open"></i></div>
Admin Management
<div className="sb-sidenav-collapse-arrow"><i className="fas fa-angle-down"></i></div>
</a>
<div className="collapse" id="collapsePages" aria-labelledby="headingTwo" data-bs-parent="#sidenavAccordion">
<nav className="sb-sidenav-menu-nested nav accordion" id="sidenavAccordionPages">
<a className="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#pagesCollapseAuth" aria-expanded="false" aria-controls="pagesCollapseAuth">
Manage Users
</a>
<a className="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#pagesCollapseAuth" aria-expanded="false" aria-controls="pagesCollapseAuth">
Create New
</a>
</nav>
</div>
</div>
</div>
<div className="sb-sidenav-footer">
<div className="small">Logged in as:</div>
Start Bootstrap
</div>
</nav>
</div>
</div>
</Fragment>
)
}
export default AdminNavigationLeft;
If the following is what you intend to be rendered:
<div id="layoutSideNav">
<div id="layoutsidenav_nav"></div>
<div id="layoutSidenav_content"></div>
</div>
Then I suspect you want the routed content to be rendered in the layoutSidenav_content div. Something like the following:
<div id="layoutSideNav">
<div id="layoutsidenav_nav">
... navbar content ...
</div>
<div id="layoutSidenav_content">
... routed content ...
</div>
</div>
In other words, the above snippet describes a layout component, the routed content is the logical place for an Outlet component wrapping nested routes to output their element content into. The route may look like:
const AdminLayout = () => (
<>
<AdminNavigation />
<div id="layoutsidenav">
<div id="layoutSidenav_nav">
<AdminNavigationLeft />
</div>
<div id="layoutsidenav_content">
<Outlet />
</div>
</div>
</>
);
<Route
path='/admin-dashboard'
element={<AdminLayout />}
>
<Route index element={<AdminDashBoardHome />} />
... other admin routes
</Route>
const AdminNavigationLeft = () => {
useEffect(() => {
document.body.classList.add('sb-nav-fixed');
}, []);
return (
<nav className="sb-sidenav accordion sb-sidenav-dark" id="sidenavAccordion">
<div className="sb-sidenav-menu">
...
</div>
</nav>
)
}
const AdminDashBoardHome = () => {
return (
<Fragment>
<main>
...
</main>
<footer className='py-4 bg-light mt-auto'>
...
</footer>
</Fragment>
)
}
I solved my own question.
You need to run the props through the component you're trying to display. The solution should be like this.
App()
<Route path='/admin-dashboard' element={<><AdminNavigation /><AdminNavigationLeft><AdminDashBoardHome/></AdminNavigationLeft></>}>
AdminDashLeft()
const AdminNavigationLeft = (props) => {
{props.children} // This is where the child component should display
}

Responsive Navbar-Toggle button not working

I am trying to do responsive navbar by using bootstrap in reactjs.I have update the show in state so as i do like show or hide the element but the toggle button is not trigger.If i use the script link in bootstrap its working but i don't want to use the scripting links and want to update manual.so help me out.
Here is my code:
import React, { Component } from "react";
export default class NavBar extends Component {
constructor(props) {
super(props);
this.state = {
show: true,
};
}
showToggle = () => {
this.setState({
show: false,
});
};
render() {
return (
<div className="container-fluid">
<div className="row">
<div className="col-lg-12 col-md-12 col-sm-12">
<nav className="navbar navbar-expand-lg navbar-dark bg-dark">
<div className="navbar-brand">
<img
alt="logo"
src="./images/or.png"
width="100px"
height="30"
className="d-inline-block align-top img-fluid"
/>
{/* <span className="nav-brand">Ortho Life Hospital</span> */}
</div>
<button
className="navbar-toggler"
type="button"
// data-toggle="collapse"
// data-target="#navbarSupportedContent"
// aria-controls="navbarSupportedContent"
// aria-expanded="false"
// aria-label="Toggle navigation"
onClick={this.showToggle}
>
<span className="navbar-toggler-icon"></span>
</button>
{this.state.show ? (
<div
className="collapse navbar-collapse"
id="navbarSupportedContent"
>
<ul className="navbar-nav ml-auto">
<li className="nav-item ml-5">
<a className="nav-link" href="/">
Home
</a>
</li>
<li className="nav-item ml-5">
<div className="dropdown">
<a
className="nav-link"
href="/about"
id="dropdownMenuButton"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
About Us
</a>
<div
className="dropdown-menu"
aria-labelledby="dropdownMenuButton"
>
<a className="dropdown-item" href="/about/#history">
History
</a>
<a className="dropdown-item" href="/about/#vision">
Vision and Mission
</a>
<a className="dropdown-item" href="/about/#whyortho">
Why Ortho?
</a>
</div>
</div>
</li>
<li className="nav-item ml-5">
<div className="dropdown">
<a
className="nav-link"
href="/department"
id="dropDownDepartment"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
Department
</a>
<div
className="dropdown-menu"
aria-labelledby="dropDownDepartment"
>
<a
className="dropdown-item"
href="/department/#medical"
>
Medical
</a>
<a
className="dropdown-item"
href="/department/#allied"
>
Allied
</a>
</div>
</div>
</li>
<li className="nav-item ml-5">
<a className="nav-link" href="/media">
Media
</a>
</li>
<li className="nav-item ml-5">
<a className="nav-link" href="/contactus">
Contact Us
</a>
</li>
</ul>
</div>
) : null}
</nav>
</div>
</div>
</div>
);
}
}

How to render the page based on selected option on the middle part of App, Top and side bar should be static

Sorry if the title is kinda confusing.
I'm making an index page with a side and top navbar with the menu using react router, I have successfully loaded the content up but I want it to load in the main body, the middle of the page.
I've tried separating method like how I used JSP before but its not very effective so to speak
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import Login from './Login';
import * as serviceWorker from './serviceWorker';
import Dropdown from 'react-bootstrap/Dropdown';
import { Link } from 'react-router-dom';
import { BrowserRouter, Route } from "react-router-dom";
import './index.css';
import AssetView from './AssetView';
import DepartmentView from './DepartmentView';
import LocationView from './LocationView';
import EmployeeView from './EmployeeView';
import AddDepartment from './AddDepartment';
import AddLocation from './AddLocation';
const routing = (
<BrowserRouter>
<div>
<nav class="navbar navbar-dark fixed-top bg-dark flex-md-nowrap p-0">
<a class="navbar-brand col-sm-3 col-md-2 mr-0" href="#">Company name</a>
<ul class="navbar-nav px-3">
<li class="nav-item dropdown">
<Dropdown>
<Dropdown.Toggle variant="success" id="dropdown-basic">
Account
</Dropdown.Toggle>
<Dropdown.Menu>
<Dropdown.Item href="#/action-1">Informations</Dropdown.Item>
<Dropdown.Item href="#/action-2">Settings</Dropdown.Item>
<Dropdown.Item href="#/action-3">Signout</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
</li>
</ul>
</nav>
<div class="container-fluid">
<div class="row">
<nav class="col-md-2 d-none d-md-block bg-light sidebar">
<div class="sidebar-sticky">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-Link active" href="#">
<span data-feather="home"></span>
Dashboard <span className="sr-only">(current)</span>
</a>
</li>
<h6 className="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
<span>Assets Management</span>
<a className="d-flex align-items-center text-muted" href="#">
<span data-feather="plus-circle" />
</a>
</h6>
<li className="nav-item">
<Link to="/AssetView">
<a class="nav-link" href="#">
<span data-feather="file"></span>
View All Assets
</a>
</Link>
</li>
</ul>
<h6 className="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
<span>Company Management</span>
<a className="d-flex align-items-center text-muted" href="#">
<span data-feather="plus-circle" />
</a>
</h6>
<ul className="nav flex-column mb-2">
<li className="nav-item">
<Link to="/DepartmentView">
<a class="nav-link" href="#">
<span data-feather="file"></span>
View All Departments
</a>
</Link>
</li>
<li className="nav-item">
<Link to="/AddDepartment">
<a class="nav-link" href="#">
<span data-feather="file"></span>
Add New Department
</a>
</Link>
</li>
<li className="nav-item">
<Link to="/LocationView">
<a class="nav-link" href="#">
<span data-feather="file"></span>
View All Locations
</a>
</Link>
</li>
<li className="nav-item">
<Link to="/AddLocation">
<a class="nav-link" href="#">
<span data-feather="file"></span>
Add New Location
</a>
</Link>
</li>
</ul>
<h6 className="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
<span>Employees Management</span>
<a className="d-flex align-items-center text-muted" href="#">
<span data-feather="plus-circle" />
</a>
</h6>
<ul className="nav flex-column mb-2">
<li className="nav-item">
<Link to="/EmployeeView">
<a class="nav-link" href="#">
<span data-feather="file"></span>
View All Employees
</a>
</Link>
</li>
</ul>
</div>
</nav>
</div>
</div>
<Route exact path="/AssetView" component={AssetView} />
<Route path="/DepartmentView" component={DepartmentView} />
<Route path="/LocationView" component={LocationView} />
<Route path="/EmployeeView" component={EmployeeView} />
<Route path="/AddDepartment" component={AddDepartment} />
<Route path="/AddLocation" component={AddLocation} />
</div>
</BrowserRouter>
)
ReactDOM.render(routing, document.getElementById('root'));
serviceWorker.unregister();
This is how the page looks right now, I really wish to make the content of the page appear in the middle
https://photos.app.goo.gl/BSuZuvGhiQQetmit5
You mean, you have to create a dashboard-like app
Where top and sidebar is static and on click of the sidebar the middle part change
Then you can check this repo
https://github.com/designrevision/shards-dashboard-react
Here is the master page https://github.com/DesignRevision/shards-dashboard-react/blob/master/src/layouts/Default.js
import React from "react";
import PropTypes from "prop-types";
import { Container, Row, Col } from "shards-react";
import MainNavbar from "../components/layout/MainNavbar/MainNavbar";
import MainSidebar from "../components/layout/MainSidebar/MainSidebar";
import MainFooter from "../components/layout/MainFooter";
const DefaultLayout = ({ children, noNavbar, noFooter }) => (
<Container fluid>
<Row>
<MainSidebar />
<Col
className="main-content p-0"
lg={{ size: 10, offset: 2 }}
md={{ size: 9, offset: 3 }}
sm="12"
tag="main"
>
{!noNavbar && <MainNavbar />}
{children}
{!noFooter && <MainFooter />}
</Col>
</Row>
</Container>
);
DefaultLayout.propTypes = {
/**
* Whether to display the navbar, or not.
*/
noNavbar: PropTypes.bool,
/**
* Whether to display the footer, or not.
*/
noFooter: PropTypes.bool
};
DefaultLayout.defaultProps = {
noNavbar: false,
noFooter: false
};
export default DefaultLayout;
The correct answer has been replied by #ravibagul91, thank you.
I removed the class="sidebar-sticky" of the sidebar and add the .sidebar{position:absolute;top:0;bottom:0} in my index.css and it works just fine as the image I just uploaded
https://photos.app.goo.gl/m744U7R4mACAUXq37
Thank you #piyush-dhamecha for the recommendation, it is somewhat similar to what I need, but truth be told, it's still kinda advance for me, but I appreciate it and will keep it for future reference.

Bulma Navbar component is not showing

I am reading Bulma docs, took example to apply it on Codesandbox but the NavBar has a problem.
I imported Bulma as mentioned in docs, copied code, and I suppose Bulma is only css framework so no js to add.
The examples of Hero section that I am using can be found over here
The example provided with Hero head and Hero body and includes Nav bar is not working. The Navbar only as you see example here
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
import "bulma/css/bulma.css";
function App() {
return (
<div className="App">
<section class="hero is-primary is-medium">
<div class="hero-head">
<nav class="navbar">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item">
<img
src="https://bulma.io/images/bulma-type-white.png"
alt="Logo"
/>
</a>
<span
class="navbar-burger burger"
data-target="navbarMenuHeroA"
>
<span />
<span />
<span />
</span>
</div>
<div id="navbarMenuHeroA" class="navbar-menu">
<div class="navbar-end">
<a class="navbar-item is-active">Home</a>
<a class="navbar-item">Examples</a>
<a class="navbar-item">Documentation</a>
<span class="navbar-item">
<a class="button is-primary is-inverted">
<span class="icon">
<i class="fab fa-github" />
</span>
<span>Download</span>
</a>
</span>
</div>
</div>
</div>
</nav>
</div>
<div class="hero-body">
<div class="container has-text-centered">
<h1 class="title">Title</h1>
<h2 class="subtitle">Subtitle</h2>
</div>
</div>
<div class="hero-foot">
<nav class="tabs">
<div class="container">
<ul>
<li class="is-active">
<a>Overview</a>
</li>
<li>
<a>Modifiers</a>
</li>
<li>
<a>Grid</a>
</li>
<li>
<a>Elements</a>
</li>
<li>
<a>Components</a>
</li>
<li>
<a>Layout</a>
</li>
</ul>
</div>
</nav>
</div>
</section>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

React - will not re render on state change

I'm all new to react.
Why does my page not re render on mouse over and mouse out when my state changes? If I look at console.log, I can see the state changes. But I can't get this to work. Here is my code:
export default class Nav extends React.PureComponent {
constructor(props) {
super(props);
this.navLevelOneId = '';
this.state = {
showSubMenu: []
};
}
// Mouse over function
handleHover = (id,event) => {
let showSubMenu=this.state.showSubMenu;
showSubMenu[id]=!showSubMenu[id]
this.setState({showSubMenu: showSubMenu}, () => {
console.log(this.state.showSubMenu);
});
}
render() {
return (
<div ref="megaMenu" className="navbar navbar-default navbar-static-top">
<div className="container">
<div className="navbar-header">
<button type="button" className="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span className="icon-bar"></span>
<span className="icon-bar"></span>
<span className="icon-bar"></span>
</button>
</div>
<div className="navbar-collapse collapse">
<ul className="nav navbar-nav">
<li onMouseOver={this.handleHover.bind(this,0)} onMouseOut={this.handleHover.bind(this,0)}>
<a>Home</a>
</li>
<li className="dropdown menu-large" onMouseOver={this.handleHover.bind(this,1)} onMouseOut={this.handleHover.bind(this,1)}>
<a className="dropdown-toggle" data-toggle="dropdown">Product Listing</a>
<ul className={"dropdown-menu megamenu row " + this.state.showSubMenu[1]}>
<li>
<div className="col-sm-6 col-md-3">
<a href="" className="thumbnail">
<img src="http://placehold.it/150x120" alt="test" />
</a>
</div>
<div className="col-sm-6 col-md-3">
<a href="" className="thumbnail">
<img src="http://placehold.it/150x120" alt="test" />
</a>
</div>
<div className="col-sm-6 col-md-3">
<a href="" className="thumbnail">
<img src="http://placehold.it/150x120" alt="test" />
</a>
</div>
<div className="col-sm-6 col-md-3">
<a href="" className="thumbnail">
<img src="http://placehold.it/150x120" alt="test" />
</a>
</div>
</li>
</ul>
</li>
<li className="dropdown menu-large" onMouseOver={this.handleHover.bind(this,2)} onMouseOut={this.handleHover.bind(this,2)}>
<a className="dropdown-toggle" data-toggle="dropdown">Categories</a>
<ul className={"dropdown-menu megamenu row " + this.state.showSubMenu[2]}>
<li>
<div className="col-sm-6 col-md-3">
<a href="" className="thumbnail">
<img src="http://placehold.it/150x120" alt="test" />
</a>
</div>
<div className="col-sm-6 col-md-3">
<a href="" className="thumbnail">
<img src="http://placehold.it/150x120" alt="test" />
</a>
</div>
<div className="col-sm-6 col-md-3">
<a href="" className="thumbnail">
<img src="http://placehold.it/150x120" alt="test" />
</a>
</div>
<div className="col-sm-6 col-md-3">
<a href="" className="thumbnail">
<img src="http://placehold.it/150x120" alt="test" />
</a>
</div>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
);
}
}
Check out the difference between using Component and PureComponent.
Briefly, PureComponent performs a shallow comparison on state change. That means that it compares only references for state objects and arrays (in your case this.state.showSubMenu is an array and it's reference doesn't change so React won't force a rerender there)

Resources