I need to change the logo when window width small than 768 but can't realize it. Must be responsive on window width changes. what is wrong with my code? thank you!
export default class Header extends Component {
constructor(props) {
super(props);
this.state = {
winWidth: 0
};
this.getWindowSize = this.getWindowSize.bind(this);
}
componentDidMount() {
this.getWindowSize();
window.addEventListener('resize', this.getWindowSize);
}
componentWillUnmount() {
window.removeEventListener('resize', this.getWindowSize);
}
getWindowSize() {
this.setState({ winWidth: window.innerWidth});
}
changeLogo(logo){
if(this.state.winWidth < 768){
logo = './images/small.png';
}
logo = './images/regular.png';
}
render() {
const {logo} = this.props;
return (
<div className="Header">
<img src={ this.changeLogo(logo) } alt="logo"/>
</div>
)
}
}