📅  最后修改于: 2022-03-11 14:58:37.182000             🧑  作者: Mango
import React, { Component } from 'react';
class App extends Component {
constructor(props) {
super(props)
this.state = { matches: window.matchMedia("(min-width: 768px)").matches };
}
componentDidMount() {
const handler = e => this.setState({matches: e.matches});
window.matchMedia("(min-width: 768px)").addListener(handler);
}
render() {
return (
{this.state.matches && (Big Screen
)}
{!this.state.matches && (Small Screen
)}
);
}
}
export default App;