Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-motion

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-motion

A spring that solves your animation problems.

  • 0.4.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is react-motion?

react-motion is a popular library for creating animations in React applications. It leverages the physics-based animation approach to create smooth and natural transitions. The library is highly flexible and allows developers to animate various properties of their components with ease.

What are react-motion's main functionalities?

Basic Animation

This example demonstrates a basic animation where a div element moves horizontally from 0 to 100 pixels using the spring function.

```jsx
import React from 'react';
import { Motion, spring } from 'react-motion';

const BasicAnimation = () => (
  <Motion defaultStyle={{ x: 0 }} style={{ x: spring(100) }}>
    {style => <div style={{ transform: `translateX(${style.x}px)` }}>Hello World</div>}
  </Motion>
);

export default BasicAnimation;
```

Staggered Motion

This example shows how to create a staggered animation where multiple items move one after another, creating a cascading effect.

```jsx
import React from 'react';
import { StaggeredMotion, spring } from 'react-motion';

const StaggeredAnimation = () => (
  <StaggeredMotion
    defaultStyles={[{ x: 0 }, { x: 0 }, { x: 0 }]}
    styles={prevInterpolatedStyles => prevInterpolatedStyles.map((_, i) => {
      return i === 0
        ? { x: spring(100) }
        : { x: spring(prevInterpolatedStyles[i - 1].x) };
    })}
  >
    {interpolatingStyles => (
      <div>
        {interpolatingStyles.map((style, i) => (
          <div key={i} style={{ transform: `translateX(${style.x}px)` }}>Item {i}</div>
        ))}
      </div>
    )}
  </StaggeredMotion>
);

export default StaggeredAnimation;
```

Transition Motion

This example demonstrates how to use TransitionMotion to animate the addition and removal of items in a list, with smooth transitions for entering and leaving elements.

```jsx
import React from 'react';
import { TransitionMotion, spring } from 'react-motion';

class TransitionAnimation extends React.Component {
  state = { items: ['a', 'b', 'c'] };

  willEnter() {
    return { opacity: 0 };
  }

  willLeave() {
    return { opacity: spring(0) };
  }

  render() {
    return (
      <TransitionMotion
        styles={this.state.items.map(item => ({ key: item, style: { opacity: spring(1) } }))}
        willEnter={this.willEnter}
        willLeave={this.willLeave}
      >
        {interpolatedStyles => (
          <div>
            {interpolatedStyles.map(config => (
              <div key={config.key} style={{ opacity: config.style.opacity }}>{config.key}</div>
            ))}
          </div>
        )}
      </TransitionMotion>
    );
  }
}

export default TransitionAnimation;
```

Other packages similar to react-motion

Keywords

FAQs

Package last updated on 31 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc