Would this help: I am using window.innerWidth
to check the width of the viewport and setting onClick
accordingly on condition.
import React from "react";
import "./styles.css";
class App extends React.Component {
constructor(props) {
super(props);
this.state = { addClass: false, vw: window.innerWidth };
}
toggle() {
console.log("Toggle Method");
}
notToggle() {
console.log("Not Toggling");
}
render() {
return (
<div
onClick={
this.vw > 800 ? this.toggle.bind(this) : this.notToggle.bind(this)
}
>
<div className="icon">Hellow Hellow</div>
</div>
);
}
}
export default App;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…