Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: useInviewport result support disconnect #2539

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

LingJinT
Copy link

@LingJinT LingJinT commented Apr 28, 2024

[中文版模板 / Chinese template]

🤔 This is a ...

  • 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. ⚠️

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

@CLAassistant
Copy link

CLAassistant commented Apr 28, 2024

CLA assistant check
All committers have signed the CLA.

@LingJinT LingJinT changed the title fix: useInViewport support once API feat: useInViewport support once API Apr 28, 2024
@LingJinT
Copy link
Author

还有人审核吗?

@crazylxr
Copy link
Collaborator

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

@LingJinT
Copy link
Author

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

可以的,我抽空改一下

@LingJinT LingJinT changed the title feat: useInViewport support once API feat: useInviewport result support disconnect Jul 15, 2024
@LingJinT
Copy link
Author

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

@crazylxr done,pls review~

@liuyib
Copy link
Collaborator

liuyib commented Jul 18, 2024

刚测了下,现在不太能实现 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
Copy link
Collaborator

liuyib commented Jul 18, 2024

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

image

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

@crazylxr 见哥,你觉着呢?

@LingJinT
Copy link
Author

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

image

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

@crazylxr 见哥,你觉着呢?

@liuyib done, pls review ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useInViewport 弄一個triggerOnce的參數比較好
4 participants