What is rc-motion?
The rc-motion npm package is a React component library designed to handle animations and transitions in a React application. It provides a simple and powerful way to implement various animations, including entering, leaving, and switching animations with customizable options for timing, easing, and more.
What are rc-motion's main functionalities?
Basic Animation
This code demonstrates how to use rc-motion to create a basic fade-in animation. The `CSSMotion` component is used with the `visible` prop set to true and a `motionName` provided to define the animation type. The children function renders the animated element with the appropriate style and className applied.
{"import React from 'react'; import CSSMotion from 'rc-motion'; function FadeInExample() { return ( <CSSMotion visible={true} motionName='fade'> {({ style, className }) => ( <div style={style} className={className}>Fade In Animation</div> )} </CSSMotion> ); } export default FadeInExample;"}
Custom Animation
This example shows how to create a custom slide animation using rc-motion. The `CSSMotion` component is configured with custom functions for `onAppearStart` and `onAppearActive` to control the animation's start and active states, respectively. This allows for more complex animations beyond predefined ones.
{"import React from 'react'; import CSSMotion from 'rc-motion'; function SlideAnimationExample() { return ( <CSSMotion visible={true} motionName='slide' motionAppear={true} onAppearStart={() => ({ height: 0 })} onAppearActive={() => ({ height: 'auto' })} > {({ style, className }) => ( <div style={style} className={className}>Slide Animation</div> )} </CSSMotion> ); } export default SlideAnimationExample;"}
Other packages similar to rc-motion
react-spring
react-spring is a spring-physics based animation library for React. It offers a more physics-based approach to animations, providing a natural and realistic feel. Compared to rc-motion, react-spring focuses more on the physics behind the animations and offers a wider range of animation controls.
framer-motion
framer-motion is a comprehensive animation library for React that makes it simple to create complex animations with a more declarative API. It supports gesture animations, SVG animations, and more. While rc-motion is focused on basic enter and leave animations, framer-motion provides a broader set of animation features and is more suited for intricate animation sequences.
rc-motion

React lifecycle controlled motion library.
Live Demo
https://react-component.github.io/motion/
Install

Example
import CSSMotion from 'rc-motion';
export default ({ visible }) => (
<CSSMotion visible={visible} motionName="my-motion">
{({ className, style }) => <div className={className} style={style} />}
</CSSMotion>
);
API
CSSMotion
motionName | string | - | Config motion name, will dynamic update when status changed |
visible | boolean | true | Trigger motion events |
motionAppear | boolean | true | Use motion when appear |
motionEnter | boolean | true | Use motion when enter |
motionLeave | boolean | true | Use motion when leave |
motionLeaveImmediately | boolean | - | Will trigger leave even on mount |
motionDeadline | number | - | Trigger motion status change even when motion event not fire |
removeOnLeave | boolean | true | Remove element when motion leave end |
leavedClassName | string | - | Set leaved element className |
onAppearStart | (HTMLElement, Event) => CSSProperties | void; | - | Trigger when appear start, return style will patch to element |
onEnterStart | (HTMLElement, Event) => CSSProperties | void; | - | Trigger when enter start, return style will patch to element |
onLeaveStart | (HTMLElement, Event) => CSSProperties | void; | - | Trigger when leave start, return style will patch to element |
onAppearActive | (HTMLElement, Event) => CSSProperties | void; | - | Trigger when appear active, return style will patch to element |
onEnterActive | (HTMLElement, Event) => CSSProperties | void; | - | Trigger when enter active, return style will patch to element |
onLeaveActive | (HTMLElement, Event) => CSSProperties | void; | - | Trigger when leave active, return style will patch to element |
onAppearEnd | (HTMLElement, Event) => boolean | void; | - | Trigger when appear end, will not finish when return false |
onEnterEnd | (HTMLElement, Event) => boolean | void; | - | Trigger when enter end, will not finish when return false |
onLeaveEnd | (HTMLElement, Event) => boolean | void; | - | Trigger when leave end, will not finish when return false |
CSSMotionList
extends all the props from CSSMotion
keys | React.Key[] | - | Motion list keys |
component | string | React.ComponentType | div | wrapper component |
Development
npm install
npm start
License
rc-motion is released under the MIT license.