hooks icon indicating copy to clipboard operation
hooks copied to clipboard

feat: useInviewport result support disconnect

Open LingJinT opened this issue 1 year ago • 9 comments

[中文版模板 / Chinese template]

🤔 This is a ...

  • [x] New feature
  • [ ] Bug fix
  • [ ] Site / documentation update
  • [ ] Demo update
  • [ ] TypeScript definition update
  • [ ] Bundle size optimization
  • [ ] Performance optimization
  • [ ] Enhancement feature
  • [ ] Internationalization
  • [ ] Refactoring
  • [ ] Code style optimization
  • [ ] Test Case
  • [ ] Branch merge
  • [ ] Other (about what?)

🔗 Related issue link

close #2531

💡 Background and solution

#2531

📝 Changelog

Language Changelog
🇺🇸 English useInViewport support disconnect
🇨🇳 Chinese useInViewport 支持disconnect

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • [x] Doc is updated/provided or not needed
  • [x] Demo is updated/provided or not needed
  • [x] TypeScript definition is updated/provided or not needed
  • [x] Changelog is provided or not needed

LingJinT avatar Apr 28 '24 01:04 LingJinT

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 28 '24 01:04 CLAassistant

还有人审核吗?

LingJinT avatar May 17 '24 06:05 LingJinT

我觉得这种方式不够灵活,直接把 disconnect 暴露出来是不是就可以了,开发者自己去关闭监听,这样他想监听几次就几次,

crazylxr avatar Jul 11 '24 01:07 crazylxr

我觉得这种方式不够灵活,直接把 disconnect 暴露出来是不是就可以了,开发者自己去关闭监听,这样他想监听几次就几次,

可以的,我抽空改一下

LingJinT avatar Jul 15 '24 03:07 LingJinT

我觉得这种方式不够灵活,直接把 disconnect 暴露出来是不是就可以了,开发者自己去关闭监听,这样他想监听几次就几次,

@crazylxr done,pls review~

LingJinT avatar Jul 15 '24 05:07 LingJinT

~~刚测了下,现在不太能实现 trigger once 的效果,初始还是会触发 2次,我再看下~~

可以实现 trigger once 效果,demo: https://codesandbox.io/s/jian-ting-yuan-su-ke-jian-qu-yu-bi-li-forked-vhwccy?file=/App.tsx

liuyib avatar Jul 18 '24 03:07 liuyib

返回值超过两个及以上时,再用数组解构就不太方便了,我推荐兼容数组解构 和 对接解构两种形式,参考:https://github.com/thebuilder/react-intersection-observer/blob/c9cef8fd0d3e611daa9697f9630d29d31d78767a/src/useInView.tsx#L133C1-L138C28

image

其他 hooks 同理,返回值多的时候都可以兼容下 数组解构 和 对接解构两种形式

@crazylxr 见哥,你觉着呢?

liuyib avatar Jul 18 '24 03:07 liuyib

返回值超过两个及以上时,再用数组解构就不太方便了,我推荐兼容数组解构 和 对接解构两种形式,参考:https://github.com/thebuilder/react-intersection-observer/blob/c9cef8fd0d3e611daa9697f9630d29d31d78767a/src/useInView.tsx#L133C1-L138C28

image

其他 hooks 同理,返回值多的时候都可以兼容下 数组解构 和 对接解构两种形式

@crazylxr 见哥,你觉着呢?

@liuyib done, pls review ~

LingJinT avatar Jul 18 '24 07:07 LingJinT