Skip to content

Commit

Permalink
feat(viewer): add useTextBox hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Seunghyeon-lunit committed Sep 27, 2022
1 parent 8eebd64 commit 5908fe1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libs/insight-viewer/src/hooks/useTextBox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useCallback, useState } from 'react'

const useTextBox = () => {
const [textBox, setTextBox] = useState<{ height: number; width: number } | null>(null)

const textBoxRef = useCallback((ref: SVGTextElement) => {
if (ref !== null) {
const { width, height } = ref.getBBox()
setTextBox({ width, height })
}
}, [])

return [textBox, textBoxRef] as const
}

export default useTextBox

0 comments on commit 5908fe1

Please sign in to comment.