raf-hook
A react hook for requestAnimationFrame()
Last updated 2 years ago by abalmos .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install raf-hook 
SYNC missed versions from official npm registry.

raf-hook

A React hook for requestAnimationFrame().

Installation

$ yarn add raf-hook

or

$ npm install --save raf-hook

Import

import { useRAF } from 'raf-hook';

Example usage

import React from 'react';
import { useRAF } from 'raf-hook';

export function MyRenderComponent({ active, fps }) {
  const reqId = useRAF(
    (ts) => {
      /*
        Runs at `fps` frames per second when `active` == true.

        ts is the frame timestamp from requestAnimationFrame
      */
    },
    active,
    fps
  );

  return (
    <div>
      The request id is <strong>{reqId}</strong>. It may be used with
      <code>window.cancelAnimationFrame</code> to cancel the request. This shouldn't
      be needed. The hook properly manages the requests based on the component's
      life cycle.
    </div>
  );
}

Current Tags

  • 0.1.2                                ...           latest (2 years ago)

3 Versions

  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 3
Dependencies (0)
None
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |