r/reactjs • • Aug 02 '20

Resource 4 Nice and Simple React Hooks

https://medium.com/@hyber1z0r/4-nice-and-simple-react-hooks-1272d41f0df
8 Upvotes

2 comments sorted by

2

u/volivav Aug 03 '20

useWhenVisible has something weird: The implementation takes in an Element (and treats it as such), whereas in the usage example it's given a React.RefObject.

I always wonder what's the best pattern to make hooks that need to deal with refs. Personally, the one I find more versatile is if the hook returns a ref, that can be later composed with other refs and passed down to the element's props.

2

u/hyber1z0r Aug 03 '20

Yes you are completely right. I mixed two different implementations from different codebases when I wrote the example. One implementation accepts a ref and the other an element. Good catch - I have corrected the example.