【发布时间】:2019-11-23 01:06:11
【问题描述】:
我有以下组件定义:
import { useRef } from 'react';
export default function useScroll() {
const ref = useRef(null)
const executeScroll = () => {
if (ref != null)
window.scrollTo(0, ref.current.offsetTop)
}
const htmlElementAttributes = { ref }
return [executeScroll, htmlElementAttributes]
}
window.scrollTo(0, ref.current.offsetTop) 行抛出错误。我已经包含if (ref != null) 检查,但没有工作。有什么想法吗?
【问题讨论】:
-
ref.current为空
标签: javascript reactjs eslint react-hooks