tldraw/packages/ui/src/lib/hooks/useHighDpiCanvas.ts
Steve Ruiz a5e653b225
Cleanup @tldraw/ui types / exports (#1504)
This PR cleans up exports from TldrawUi, unifying types under `TLUi` and
removing many items from exports / marking others as internal.

### Change Type

- [x] `major` — Breaking Change

### Release Notes

- [editor] clean up / unify types
2023-06-02 21:16:09 +00:00

14 lines
397 B
TypeScript

import { useLayoutEffect } from 'react'
/** @internal */
export function useHighDpiCanvas(ref: React.RefObject<HTMLCanvasElement>, dpr: number) {
// Match the resolution of the client
useLayoutEffect(() => {
const canvas = ref.current
if (!canvas) return
const rect = canvas.getBoundingClientRect()
canvas.width = rect.width * dpr
canvas.height = rect.height * dpr
}, [ref, dpr])
}