をこのような画面サイズの変更はcomponentWillMountの方が良い方法があると確信していますが、これはうまくいきます。
toggleOpenDrawer =() => {
if (!this.state.mobile) {
return;
}
this.setState({
open: !this.state.open
})
}
setSmall =() => {
this.setState({open: false, docked: false, mobile: true})
}
setLarge =() => {
this.setState({open: true, docked: true, mobile: false})
}
componentWillMount() {
const mediaQuery = window.matchMedia('(min-width: 768px)');
if (mediaQuery.matches) {
this.setLarge()
} else {
this.setSmall()
}
mediaQuery.addListener((mq) => {
if (mq.matches) {
this.setLarge()
} else {
this.setSmall()
}
});
}