GithubHelp home page GithubHelp logo

tseijp / refr Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 8.29 MB

🌃 request animation frame

Home Page: https://refr.tsei.jp

License: MIT License

TypeScript 100.00%
react animation frame hooks raf reactive reactjs requestanimationframe solid solidjs

refr's Introduction

🔮refr

npm npm npm

  • Performance: It's the fastest way to animate in React. It doesn't have to go through the React reconciler.
  • Familiar: It's a hook, so you can use it in any function component.
  • Simple: It's just a single function that you can call from anywhere.
  • Predictable: You can cancel your animation at any time and it will run at 60fps.
  • Composable: You can use it in conjunction with the state hook to create animations.
  • Extensible: You can write your own hooks that depend on it.
  • Flexible: You can use it to schedule updates or to set timeouts.

It's just a single function that you can call from anywhere. It's a hook that will run on every frame and give you the time delta. If you return true it will keep running, otherwise it will cancel.

You can also use it to set timeouts that will run on the next frame. This is useful when you want to force an update after a state change.


Installation

npm install refr

Documentation

Docs : refr Introduction
API : refr API and feature
Guide : refr Getting Started

Ecosystem

🌇 glre: GLSL Reactive Engine
⛪️ reev: reactive event state manager

Staying informed

@tseijp twitter
tsei.jp articles

PRs

welcome✨

API

import frame from 'refr'

// Schedule an update
frame.mount((dt) => {})

// Start an update loop
frame.mount((dt) => true)

// Cancel an update
frame.cancel(fn)

// Start the update loop
frame.start()

// Pause the update loop
frame.pause()

// Stop the update loop
frame.stop()

// Restart the update loop
frame.restart()

// Set a timeout that runs on nearest frame
frame.setTimeout(() => {}, 1000)

// Get the current time
frame.now() // => number

Getting Started

import { useRef } from 'react'
import { useFrame } from 'refr'

function TrailSphere() {
        const ref = useRef()

        // Schedule an update
        useFrame((ts) => {})

        // Start an update loop
        useFrame((ts) => true)
}

License

MIT

refr's People

Contributors

tseijp avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.