@anthood/use-canvas
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Collection of react hooks to deal with canvas.

useCanvasSequence

Just import the hook and use in your react component. Make sure to supply it with a canvas element, and an array of img-src's.

You can now call render with any frame to display.

demo

See it in action connected to a scroll-listener from framer-motion

import { useCanvasSequence } from  "@anthood/use-canvas"

function MyComponent() {
    const canvasRef = useRef<HTMLCanvasElement>(null)
    const { images, allImagesLoaded, render } = useCanvasSequence(canvasRef.current,sequence)

    const onSliderChange = (value: number): void => {
    const ctx = canvasRef.current?.getContext("2d")
    if (ctx) render(images[value], ctx)
  }

    return <canvas ref={canvasRef} />
}

Package Sidebar

Install

npm i @anthood/use-canvas

Homepage

anthood.com

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

7.63 kB

Total Files

7

Last publish

Collaborators

  • anthood