React Simple Animate
React Simple Animate is a lightweight library providing declarative animation capabilities for React applications. It enables developers to implement animations from style A to style B, CSS keyframes animations, and chain multiple animations into sequences. Currently stable at version 3.5.3, it maintains an active release cadence with frequent minor updates focusing on bug fixes, type improvements, and React version compatibility, including support for React 19. Key differentiators include its minimal footprint and lack of external dependencies beyond React itself, making it an efficient choice for adding performant UI animations without bloat. It provides both component-based (`Animate`, `AnimateKeyframes`, `AnimateGroup`) and hook-based (`useAnimate`, `useAnimateKeyframes`, `useAnimateGroup`) APIs to suit different development styles, offering flexibility for both simple transitions and complex choreographed sequences.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'onComplete') or onComplete callback not firing.
cause A bug in the `useAnimate` hook prevented the `onComplete` callback from being called reliably in versions prior to 3.5.2.fixUpdate `react-simple-animate` to version `3.5.2` or newer. -
Animation not re-running or updating after state change when using `useAnimateKeyframes`.
cause The `useAnimateKeyframes` hook failed to respond correctly to component state updates in versions prior to 3.3.11.fixUpdate `react-simple-animate` to version `3.3.11` or newer. -
Animations in `AnimateGroup` are overlapping or not playing in the correct sequence/timing.
cause A bug in `AnimateGroup` affected the timing and delay mechanisms for sequenced animations in versions prior to 3.3.9.fixUpdate `react-simple-animate` to version `3.3.9` or newer.
Warnings
- breaking The type definition for the `Style` prop was updated in v3.4.0. If you were previously using custom type definitions for animation styles, they might no longer be compatible, as the prop is now strictly typed as `React.CSSProperties`.
- gotcha The `onComplete` callback within the `useAnimate` hook previously had a bug where it might not have fired correctly or consistently.
- gotcha When using `useAnimateKeyframes`, there was a known issue where animations might not re-run or update correctly when component state changes.
- gotcha `AnimateGroup` had a bug affecting time delays between sequenced animations, potentially causing incorrect timing or overlaps.
- gotcha Ensure your React and React-DOM versions are compatible with the library's peer dependencies. Newer versions of `react-simple-animate` explicitly support React 17, 18, and 19.
Install
-
npm install react-simple-animate -
yarn add react-simple-animate -
pnpm add react-simple-animate
Imports
- Animate
import Animate from 'react-simple-animate'
import { Animate } from 'react-simple-animate' - useAnimate
const useAnimate = require('react-simple-animate').useAnimateimport { useAnimate } from 'react-simple-animate' - AnimateKeyframes
import AnimateKeyframes from 'react-simple-animate'
import { AnimateKeyframes } from 'react-simple-animate' - AnimateGroup
import { AnimateGroup } from 'react-simple-animate'
Quickstart
import React from "react";
import { Animate, AnimateKeyframes, AnimateGroup } from "react-simple-animate";
export default () => (
<>
{/* animate individual element. */}
<Animate play start={{ opacity: 0 }} end={{ opacity: 1 }}>
<h1>React simple animate</h1>
</Animate>
{/* animate keyframes with individual element. */}
<AnimateKeyframes
play
iterationCount="infinite"
keyframes={["opacity: 0", "opacity: 1"]}
>
<h1>React simple animate with keyframes</h1>
</AnimateKeyframes>
{/* animate group of animation in sequences */}
<AnimateGroup play>
<Animate start={{ opacity: 0 }} end={{ opacity: 1 }} sequenceIndex={0}>
first
</Animate>
<Animate start={{ opacity: 0 }} end={{ opacity: 1 }} sequenceIndex={1}>
second
</Animate>
<Animate start={{ opacity: 0 }} end={{ opacity: 1 }} sequenceIndex={2}>
third
</Animate>
</AnimateGroup>
</>
);