React Lifecycle Motion

2.9.5 · deprecated · verified Sun Apr 19

rc-motion is a React library designed to provide granular control over component entry, exit, and update animations by leveraging React's lifecycle methods. It enables developers to integrate CSS transition classes or custom JavaScript animation callbacks to manage the visual state of components as they appear, enter, leave, or disappear from the DOM. The package, at version 2.9.5, offers a robust set of features for orchestrating complex animation sequences and serves as a foundational component within the Ant Design ecosystem. Its API, centered around properties like `motionName`, `visible`, and comprehensive lifecycle callbacks (`onAppearStart`, `onEnterEnd`, etc.), emphasizes precise control over animation flow. However, developers should be aware that this specific package (`rc-motion`) has been superseded by `@rc-component/motion` (v1.x), which represents its actively maintained and developed successor.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of CSSMotion with state-driven visibility, custom motion classes, and lifecycle callbacks.

import React, { useState } from 'react';
import { CSSMotion } from 'rc-motion';

function MyAnimatedComponent() {
  const [visible, setVisible] = useState(true);

  return (
    <div>
      <button onClick={() => setVisible(prev => !prev)}>
        Toggle Motion
      </button>
      <CSSMotion
        visible={visible}
        motionName="my-fade"
        onAppearStart={() => console.log('Appear Start')}
        onAppearActive={() => console.log('Appear Active')}
        onAppearEnd={() => console.log('Appear End')}
        onEnterStart={() => console.log('Enter Start')}
        onEnterActive={() => console.log('Enter Active')}
        onEnterEnd={() => console.log('Enter End')}
        onLeaveStart={() => console.log('Leave Start')}
        onLeaveActive={() => console.log('Leave Active')}
        onLeaveEnd={() => console.log('Leave End')}
        removeOnLeave={true}
      >
        {({ className, style }) => (
          <div
            className={className}
            style={{ ...style, padding: '20px', border: '1px solid blue', backgroundColor: 'lightblue' }}
          >
            Hello, Motion!
          </div>
        )}
      </CSSMotion>
    </div>
  );
}

export default MyAnimatedComponent;

view raw JSON →