Array of refs
danilowoz opened this issue · 5 comments
First of all, awesome package, pretty useful!
I would like to ask, is there any to use with an array of refs? Or any workaround?
I have a dynamic list and I want to know what is the current index which is in the viewport, does make sense?
So some ideas just came up in my mind:
const [arrayOfBoolean, arrayOfRefs] = useIsInViewport()
Thanks
Hey! Thanks!
So, IIUC, you have multiple dom nodes you want to track the visibility of in the window viewport?
Yes, that's the idea. Plus the array might change.
I know that I can use the "hook" into the component of the array itself, but I would like to know if there is an official way to handle this case.
So, useIsInViewport
is designed to be used once per component you want to track the visibility of. It won't ever return an array of bools and refs. But you can definitely build a custom hook of your own that's built on top of useIsInViewport
to achieve that. For e.g., you can write a custom hook that accepts some number n
and returns those many visibility refs and bools that you can then use the way you want.
We can also pair on the custom hook for your use case in this issue.
Just a heads up @danilowoz, in case of no activity on this by 26 June 2021, I'll go ahead and close it.
No problem at all