我正在检查用户是否在小于 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);}任何帮助,将不胜感激
添加回答
举报
0/150
提交
取消
