Welcome aboard! We are happy you are here and wish you good net-raft!
import React from 'react';
class App extends React.Component {
constructor() {
super();
this.state = {
data: []
}
this.setStateHandler = this.setStateHandler.bind(this);
};
setStateHandler() {
var isMobile = window.innerWidth <= 500
if (isMobile) {
this.setState({data: "mobile"})
} else {
this.setState({data: "something else"})
}
};
render() {
return (
<div>
<button onClick = {this.setStateHandler}>Click</button>
<h2>{this.state.data}</h2>
</div>
);
}
}
export default App;
The most helpful REACT solutions