import React, { Component } from "react";
class NavBtn extends Component {
state = {
styles: {
width: 0,
}
};
handleClick = () => {
this.setState(oldState => {
return {
styles: {
width: oldState.width + 100,
}
};
});
};
render() {
return (
<div>
{/* navigation icon */}
<div className="navbtn" onClick={this.handleClick}>
<div className="bar" />
<div className="bar" />
<div className="bar" />
</div>
{/* form pannel */}
<div
className="formPannel-container"
style={{ width: `${this.state.styles.width}px` }}
/>
</div>
);
}
}
export default NavBtn;
why doesn’t my setState not set a new state with this code above. It’s not accessing plus changing it and I don’t know why.
Thank you!
Silas