npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

use-tela

v1.0.0

Published

<!-- package-name end -->

Readme

use-tela

Installation

# Yarn
yarn add use-tela

# NPM
npm install use-tela

Usage

useTela provides functionality to draw on a canvas. It requires to pass a width and a height value. The hook scales the canvas based on passed dimensions and the device displayPixelRatio.

The core functionality can be accessed by setting the draw attribute: it is a callback that accepts a TelaEvent. If loop is set to true, draw function will be called for every animation frame, otherwise it will be called once.

import { useTela } from "use-tela"

const App = () => {
  const ref = useTela({
    width: 400,
    height: 400,
    loop: true,

    draw: (event) => {
      const ctx = event.canvas.getContext("2d")
      ...
    }
  })
  return <canvas ref={ref} />
}

In order to bind the hook to a canvas, you can pass a ref

const ref = useRef()
useTela({ ref, ... })
return <canvas ref={ref} />

or use the returned one:

const ref = useTela({ ... })
return <canvas ref={ref} />

Options

interface TelaOptions {
  /** Tela width */
  width: number;
  /** Tela height */
  height: number;
  /** Max devicePixelRatio value. Default is `4` */
  maxDpr?: number;

  /**
   * Ref holding the canvas element. If you omit
   * it, `useTela` will create and return one for you
   */
  ref?: React.RefObject<HTMLCanvasElement>;

  /** Enables drawing loop when `true`. Default is `false` */
  loop?: boolean;

  /**
   * Callback called for every loop frame (when `loop` is `true`)
   * and when the canvas resizes
   */
  draw?: (ev: TelaEvent) => void;
  /**
   * Callback called when the canvas resizes
   */
  onResize?: (ev: TelaEvent) => void;
}

Event

Event passed to useTela callbacks (see draw or onResize). It holds informations about the canvas, the loop (such as elapsed time) and user interaction (such as mouse position).

interface TelaEvent {
  /** The canvas DOM element */
  canvas: HTMLCanvasElement;
  /** Tela width */
  width: number;
  /** Tela height */
  height: number;
  /** Elapsed time from first `useTela` call */
  time: number;
  /** Mouse position */
  mouse: Point2;
}