Convert Figma logo to code with AI

jondot logoreact-flight

The best way to build animation compositions for React.

2,818
97
2,818
57

Top Related Projects

227,213

The library for web and native user interfaces.

124,777

The React Framework

29,083

Build Better Websites. Create modern, resilient user experiences with web fundamentals.

17,089

The App Framework for Startups

13,599

⚡️ The Missing Fullstack Toolkit for Next.js

55,199

The best React-based framework with performance, scalability and security built in.

Quick Overview

React Flight is a lightweight animation library for React applications. It provides a simple and intuitive API for creating smooth, performant animations with minimal code. React Flight is designed to work seamlessly with React components and can be easily integrated into existing projects.

Pros

  • Easy to use and integrate with React applications
  • Lightweight and performant
  • Flexible API that supports various animation types
  • Good documentation and examples

Cons

  • Limited community support compared to more established animation libraries
  • May not be suitable for complex, multi-stage animations
  • Lacks some advanced features found in larger animation libraries

Code Examples

Creating a simple fade-in animation:

import { Flight } from 'react-flight';

const FadeIn = () => (
  <Flight
    from={{ opacity: 0 }}
    to={{ opacity: 1 }}
    duration={1000}
  >
    <div>Hello, World!</div>
  </Flight>
);

Animating multiple properties:

import { Flight } from 'react-flight';

const ScaleAndRotate = () => (
  <Flight
    from={{ scale: 0.5, rotate: 0 }}
    to={{ scale: 1, rotate: 360 }}
    duration={1500}
    easing="easeInOutQuad"
  >
    <div>Scaling and rotating element</div>
  </Flight>
);

Using keyframes for more complex animations:

import { Flight } from 'react-flight';

const Bounce = () => (
  <Flight
    keyframes={[
      { translateY: 0 },
      { translateY: -30 },
      { translateY: 0 },
    ]}
    duration={800}
    iterationCount="infinite"
  >
    <div>Bouncing element</div>
  </Flight>
);

Getting Started

To start using React Flight in your project, follow these steps:

  1. Install the package:

    npm install react-flight
    
  2. Import the Flight component in your React file:

    import { Flight } from 'react-flight';
    
  3. Use the Flight component to wrap the elements you want to animate:

    const AnimatedComponent = () => (
      <Flight
        from={{ opacity: 0, translateY: 20 }}
        to={{ opacity: 1, translateY: 0 }}
        duration={500}
      >
        <div>Animated content</div>
      </Flight>
    );
    
  4. Customize the animation properties as needed, such as duration, easing, and delay.

Competitor Comparisons

227,213

The library for web and native user interfaces.

Pros of React

  • Larger community and ecosystem, with extensive documentation and third-party libraries
  • More mature and stable, with regular updates and long-term support from Facebook
  • Wider adoption in industry, leading to better job prospects and resources

Cons of React

  • Steeper learning curve, especially for beginners
  • More complex setup and configuration for larger projects
  • Heavier bundle size, which can impact performance for smaller applications

Code Comparison

React:

import React from 'react';

function App() {
  return <div>Hello, World!</div>;
}

React Flight:

import { Animate } from 'react-flight';

const App = () => (
  <Animate>
    <div>Hello, World!</div>
  </Animate>
);

Summary

React is a more established and widely-used library with a larger ecosystem, while React Flight focuses on providing smooth animations and transitions. React offers more flexibility and is suitable for a wide range of applications, but it may be overkill for simpler projects. React Flight, on the other hand, is more specialized and easier to set up for animation-heavy applications, but has a smaller community and fewer resources available.

124,777

The React Framework

Pros of Next.js

  • More comprehensive framework with built-in routing, server-side rendering, and API routes
  • Larger community and ecosystem, with extensive documentation and third-party integrations
  • Regular updates and maintenance from Vercel, ensuring long-term support and improvements

Cons of Next.js

  • Steeper learning curve due to its more complex architecture and features
  • Less flexibility in project structure compared to React Flight's minimal approach
  • Potentially heavier bundle size for simpler applications that don't require all features

Code Comparison

Next.js:

// pages/index.js
export default function Home() {
  return <h1>Welcome to Next.js!</h1>
}

React Flight:

// App.js
import React from 'react'
import { Animate } from 'react-flight'

const App = () => (
  <Animate>
    <h1>Welcome to React Flight!</h1>
  </Animate>
)

Next.js provides a more structured approach with file-based routing, while React Flight focuses on animation components within a standard React application. Next.js offers a complete framework for building web applications, whereas React Flight is a specialized library for creating smooth animations and transitions in React projects.

29,083

Build Better Websites. Create modern, resilient user experiences with web fundamentals.

Pros of Remix

  • Full-stack framework with server-side rendering and data loading
  • Built-in routing system with nested routes
  • Optimized for performance with automatic code splitting

Cons of Remix

  • Steeper learning curve due to its full-stack nature
  • Less flexibility in choosing backend technologies

Code Comparison

Remix (server-side data loading):

export async function loader({ params }) {
  const user = await getUser(params.id);
  return json({ user });
}

export default function UserProfile() {
  const { user } = useLoaderData();
  return <h1>{user.name}</h1>;
}

React Flight (client-side data fetching):

function UserProfile({ id }) {
  const { data: user } = useSWR(`/api/users/${id}`, fetcher);
  return <h1>{user?.name}</h1>;
}

Key Differences

  • Remix focuses on server-side rendering and data loading, while React Flight is primarily for client-side rendering
  • Remix provides a more opinionated, full-stack approach, whereas React Flight offers more flexibility in architecture
  • Remix includes built-in routing and data management, while React Flight relies on additional libraries for these features

Use Cases

  • Choose Remix for full-stack applications with server-side rendering requirements
  • Opt for React Flight when building client-side applications with more flexibility in backend choices
17,089

The App Framework for Startups

Pros of Redwood

  • Full-stack framework with integrated backend and frontend
  • Built-in CLI for scaffolding and code generation
  • Opinionated structure for faster development and easier onboarding

Cons of Redwood

  • Steeper learning curve due to its comprehensive nature
  • Less flexibility compared to React Flight's lightweight approach
  • Potentially overkill for smaller projects or simple applications

Code Comparison

Redwood (Pages):

import { Link, routes } from '@redwoodjs/router'

const HomePage = () => {
  return (
    <>
      <h1>Welcome to Redwood</h1>
      <Link to={routes.about()}>About</Link>
    </>
  )
}

export default HomePage

React Flight (Component):

import React from 'react'
import { Animate } from 'react-flight'

const MyComponent = () => (
  <Animate
    from={{ opacity: 0 }}
    to={{ opacity: 1 }}
    config={{ duration: 1000 }}
  >
    <h1>Hello, React Flight!</h1>
  </Animate>
)

export default MyComponent

While Redwood focuses on full-stack development with integrated routing and structure, React Flight specializes in animations and transitions for React components. Redwood offers a more comprehensive solution, while React Flight provides a lightweight library for specific animation needs.

13,599

⚡️ The Missing Fullstack Toolkit for Next.js

Pros of Blitz

  • Full-stack React framework with built-in authentication, database integration, and API layer
  • Zero-API approach simplifies development by eliminating the need for a separate API
  • Active community and regular updates

Cons of Blitz

  • Steeper learning curve due to its comprehensive nature
  • Less flexibility compared to more lightweight solutions
  • Opinionated structure may not suit all project types

Code Comparison

React Flight:

import { Animate } from 'react-flight';

<Animate
  animateOnMount={true}
  durationSeconds={0.5}
  translateY={[-20, 0]}
  opacity={[0, 1]}
>
  <div>Animated content</div>
</Animate>

Blitz:

import { useMutation } from 'blitz';
import createUser from 'app/users/mutations/createUser';

const [createUserMutation] = useMutation(createUser);

const handleSubmit = async (values) => {
  await createUserMutation(values);
};

Key Differences

React Flight focuses on animation and UI transitions, while Blitz is a comprehensive full-stack framework. React Flight is more suitable for projects requiring advanced animations, whereas Blitz is better for building complete web applications with server-side rendering and database integration.

55,199

The best React-based framework with performance, scalability and security built in.

Pros of Gatsby

  • Full-featured static site generator with a rich ecosystem of plugins and themes
  • Built-in performance optimizations like code splitting and image optimization
  • Strong community support and extensive documentation

Cons of Gatsby

  • Steeper learning curve due to its complexity and reliance on GraphQL
  • Slower build times for large sites compared to simpler static site generators

Code Comparison

Gatsby:

import React from "react"
import { Link } from "gatsby"

export default function Home() {
  return <Link to="/about/">About</Link>
}

React Flight:

import React from "react"
import { Link } from "react-flight"

export default function Home() {
  return <Link to="/about">About</Link>
}

Key Differences

  • Gatsby is a full-fledged static site generator, while React Flight is a lightweight routing library
  • Gatsby uses GraphQL for data fetching, whereas React Flight relies on standard React patterns
  • Gatsby offers more built-in features and optimizations out of the box
  • React Flight provides a simpler, more focused solution for routing in React applications

Use Cases

  • Choose Gatsby for complex static sites or blogs with rich content and data requirements
  • Opt for React Flight when building single-page applications with simple routing needs and minimal setup

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

https://jondot.github.io/react-flight/

The best way to build animation compositions for React. Design and compose a component to start with, a component to end with, and Flight will take it from there.

Flight tries to be for React what Principle is for Sketch compositions - the fastest, most friction free way to compose and an effortless way to animate an idea, an interaction, or a short movie-like composition in a self-contained widget (a React component after all).

Check out the new video:

React Flight in Three Minutes

Quick Start (From Scratch)

Just clone and use the example, built around create-react-app:

$ git clone https://github.com/jondot/react-flight
$ cd react-flight/examples/compos
$ yarn && yarn start

Quick Start (Existing Project)

With yarn (or npm):

$ yarn add react-flight
$ curl https://raw.githubusercontent.com/jondot/react-flight/master/examples/compos/src/index.js -o src/anim.js

And now you can frame your compositions in anim.js, require and place it in any other React component.

Next:

  1. Add jQuery (or Zepto, or any jQuery drop-in) if you don't have it already in the project.
  2. Or if you use create-react-app you can add it to your public/index.html, like here, or eject and configure webpack for jQuery.

NOTE: jQuery is currently a requirement of one of react-flight's dependencies. We plan to rebuild that dependency any way, obsoleting this requirement in the process (also: PRs accepted!).

Workflow

When you're designing compositions, focus on designing frames. The first frame is marked source because that's the starting point, and interactive because you want to play with it while you go.

  <Flight interactive ref={flight => (this.flight = flight)}>
    <Flight.Frame duration={300} source interactive showFrames>

Showing Frames

While designing, you want to have showFrames on. It will unpack all of the frames in front of you, so you could edit them while watching them. With Webpack hot-reload this becomes a fantastic experience.

When done, remove showFrames.

Controlling Flight Directly

This is where the ref addition comes in:

  <Flight interactive ref={flight => (this.flight = flight)}>
    <Flight.Frame duration={300} source interactive showFrames>

Once you can grab an instance of flight you can flight.play() and flight.reset() on demand from your own components and actions.

Here's a full layout:

  <Flight interactive ref={flight => (this.flight = flight)}>
    <Flight.Frame duration={300} source interactive showFrames>

      -- your own DOM / React Components ---
      -- starting position and styles    ---

    </Flight.Frame>

    <Flight.Frame>

      -- your own DOM / React Components ---
      -- ending position and styles    ---

    </Flight.Frame>
  </Flight>

Redux

If you're using Redux, there's basic support for it. Basic in the sense that react-flight is not going to handle deep renders of a stateful app with all its gotchas, so YMMV.

You can check out this Redux example for a fully working solution.

For your app, you can enable Redux support by indicating inclusion of store before using the Flight component:

Flight.contextTypes = {
  store: PropTypes.object,
}

Flight.childContextTypes = {
  ...Flight.childContextTypes,
  store: PropTypes.object,
}

Under the Hood

If you want to hack on react-flight, here are some context to keep in mind.

react-flight does some cool stuff and some DOM-heavy stuff (perhaps less cool?). For the cool stuff, it walks the component tree, makes decisions about what should move where, and builds a clean and nice declarative data structure that represents the way compositions should behave.

Currently it will then hand over this data to a DOM-based adapter, that also uses Velocity.js, so that it would actually orchestrate the animations. This is where you're welcome to plug in your own adapter - another animation engine, React Native, and what not.

Happy hacking!

Contributing

Fork, implement, add tests, pull request, get my everlasting thanks and a respectable place here :).

Thanks:

To all Contributors - you make this happen, thanks!

Copyright

Copyright (c) 2017 Dotan Nahum @jondot. See LICENSE for further details.

NPM DownloadsLast 30 Days