我正在檢查用戶是否在小于 768px 的設備上,如果他們是我想將 isTop 設置為 false。我遇到了一些問題。一切看起來都很好,但我不斷收到此錯誤:類型錯誤:_this2.state.isTop 不是函數我在做什么:componentDidMount() { this.updateWindowDimensions(); window.addEventListener('resize', this.updateWindowDimensions); document.addEventListener('scroll', () => { const isTop = window.scrollY < window.innerHeight - 50; if (isTop !== this.state.isTop) { this.setState({ isTop }) } }); this.checkWidth = () => { const match = window.matchMedia(`(max-width: 768px)`); if (match) { this.state.isTop(false); } }; this.checkWidth(); window.addEventListener('resize', this.checkWidth);}任何幫助,將不勝感激
如何將 state 屬性設置為 false
慕的地8271018
2021-06-29 01:16:46