kopia lustrzana https://github.com/Tldraw/Tldraw
15 wiersze
395 B
TypeScript
15 wiersze
395 B
TypeScript
import { useLayoutEffect } from 'react'
|
|
|
|
/** @public */
|
|
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])
|
|
}
|