Skip to content

Instantly share code, notes, and snippets.

@elzup
Created June 14, 2021 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elzup/f7805a581fea36355d1e1c8ee953b50c to your computer and use it in GitHub Desktop.
Save elzup/f7805a581fea36355d1e1c8ee953b50c to your computer and use it in GitHub Desktop.
fitty for react
import { useEffect, useRef } from 'react'
import fitty from 'fitty'
export function useFitty() {
const ref = useRef<HTMLDivElement>(null)
useEffect(() => {
if (!ref.current) return
fitty(ref.current)
ref.current.addEventListener('fit', (e) => {
console.log(e)
})
}, [ref.current])
return [ref] as const
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment