microlinkhq / sdk

Make any URL embeddable. Turn any URL into a beautiful link preview.
https://microlink.io/sdk
MIT License
575 stars 38 forks source link

fix: linter warning #329

Closed Kikobeats closed 6 months ago

Kikobeats commented 7 months ago

I noted this warning

  162:3  warning  React Hook useEffect has a missing dependency: 'toFetchData'. Either include it or remove the dependency array  react-hooks/exhaustive-deps

We excluded toFetchData from the hook dependencies because otherwise it creates an infinite loop. I was digging what is causing that and I noted it comes from useIntersectionObserver since it returns a ref and it's being attached to a CardWrap element, creating the loop.

I think our useIntersectionObserver is based on this one: https://github.com/uidotdev/usehooks/blob/dfa6623fcc2dcad3b466def4e0495b3f38af962b/index.js#L512

What I did for fixing this is to simply pas ref as argument, similar to this implementation: https://github.com/streamich/react-use/blob/e27c1930da8b94a2c570954786aa68a3dc5624be/src/useIntersection.ts#L4

vercel[bot] commented 7 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sdk-hover-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 9, 2023 5:47pm
sdk-hover-vanilla ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 9, 2023 5:47pm
sdk-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 9, 2023 5:47pm
sdk-vanilla ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 9, 2023 5:47pm