alibaba / hooks

A high-quality & reliable React Hooks library. https://ahooks.pages.dev/
https://ahooks.js.org/
MIT License
13.91k stars 2.69k forks source link

useInViewport不能正确监听ref变动 #568

Closed sqchenxiyuan closed 2 years ago

sqchenxiyuan commented 4 years ago

初次渲染useInViewport获取的ref没有绑定对应的dom,后续绑定都无效

https://codesandbox.io/s/eloquent-tdd-ldp7l?fontsize=14&hidenavigation=1&theme=dark

2

也许可以通过如下方式来检测变化

const [ el, setEl ] = useState(getTargetElement(target))

useEffect(() => {
  setEl(getTargetElement(target))
})

useEffect(() => {
   //...
}, [el]);
SpiritQAQ commented 4 years ago

我是从umi-hooks迁移过来出现了这个问题...

brickspert commented 2 years ago

Hello:

这个问题我们已经在 v3.0 版本彻底修复,目前 v3.0 版本已经发布 alpha 版本。

欢迎试用。

文档:https://ahooks-next.surge.sh/ 源码:https://github.com/alibaba/hooks/tree/next

安装最新分支

$ npm install --save ahooks@next
# or
$ yarn add ahooks@next

We have fixed this problem in the v3.0 version, and the alpha has been released.

Welcome to try.

Doc:https://ahooks-next.surge.sh/ Source Code:https://github.com/alibaba/hooks/tree/next

Install v3.0

$ npm install --save ahooks@next
# or
$ yarn add ahooks@next