Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
how to make sidebar toggle works on react.js
import React, { Component } from 'react';
import './SideBar.css'



class SideBar extends Component {
    state = {
    }
    

    render() { 
    
        var toggleOptions = false
        var sideBar = document.querySelector('#sideBar');
        
        const toggleOptionsOnClick = (e) => {
            e.preventDefault()
            switch(toggleOptions) {
                case false :
                    toggleOptions = true
                    sideBar.setAttribute('id', 'openedSideBar')
                case true :
                    toggleOptions = false
                    sideBar.setAttribute('id', 'sideBar')
                default :
                    

            }
        }
        console.log(sideBar);
    
    

        return (
            <nav id="sideBar">

                <div id='container' 
                onClick={this.toggleOptionsOnClick} 
                style={{cursor:'pointer'}}
                >
                    <div className='burger'></div>
                    <div className='burger'></div>
                    <div className='burger'></div>
                </div>



                


            </nav>
        );
    }
}

export default SideBar;

This is my sidebar react component and everything is fine, no errors no bugs ... but when i click the hamburger options div it don't do the method that change the sidebar id attribute. Anyone knows why ? Note : the console.log command returns null

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!