This is Header component with React-Bootstrap. I created a menu icon with pure CSS but I want to change the icon function onClick but I'm getting the error - TypeError: Cannot read property 'toggle' of undefined
. It's there any way I'm getting it wrongly? Kindly check. Thanks.
Also, it's there a way, I can handle this with React Hooks method instead?
Thanks.
import styles from './Landing.module.css';
import './Landing.module.css';;
const openMenu = (open) => {
open.classList.toggle('change');
};
<Nav className="ml-auto">
<div className={styles.allMenus}>
<div className="menuIcon" onClick={openMenu}>
<div className={styles.bar1}></div>
<div className={styles.bar2}></div>
<div className={styles.bar3}></div>
</div>
</div>
</Nav>
My CSS - It has the change styles
div[class="menuIcon"] {
background-color: #ffffff;
padding: 13px;
margin-right: 46px;
float: right;
cursor: pointer;
}
.bar1, .bar2, .bar3 {
width: 32px;
height: 3px;
background-color: #333;
margin: 6px 0;
transition: 0.4s;
}
.change .bar1 {
-webkit-transform: rotate(-45deg) translate(-9px, 6px) ;
transform: rotate(-45deg) translate(-9px, 6px) ;
}
.change .bar2 {
opacity: 0;
}
.change .bar3 {
-webkit-transform: rotate(45deg) translate(-8px, -8px) ;
transform: rotate(45deg) translate(-8px, -8px) ;
}
question from:
https://stackoverflow.com/questions/65924063/how-to-toggle-css-styles-with-toggle-method-in-react 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…