React Tween State Animation Library

0.1.5 · abandoned · verified Wed Apr 22

react-tween-state is an animation utility for React applications that enables smooth interpolation of component state values over time. It provides a `this.tweenState` method, which functions similarly to `this.setState`, but initiates an animated transition of a state property to a target value over a specified duration. The library relies heavily on React's deprecated mixin system (`React.createClass`) for integration into components. The current and likely final stable version is 0.1.5, released in 2016, and the project has been unmaintained since then. Its core differentiators, such as direct state manipulation via mixins and an imperative `tweenState` API, are now considered anti-patterns in modern React development, which favors declarative component-based animation libraries and hooks. It does not support newer React features or functional components.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to integrate `react-tween-state` using a `React.createClass` component with its mixin, animate a state property (`left`), and retrieve the tweening value during render. This requires an older React setup.

const tweenState = require('react-tween-state');
const React = require('react');
const ReactDOM = require('react-dom'); // Required for rendering

const App = React.createClass({
  mixins: [tweenState.Mixin],
  getInitialState: function() {
    return { left: 0 };
  },
  handleClick: function() {
    // Animate 'left' property of the state
    this.tweenState('left', {
      easing: tweenState.easingTypes.easeInOutQuad,
      duration: 500,
      endValue: this.state.left === 0 ? 400 : 0,
      onEnd: () => console.log('Animation ended!')
    });
  },
  render: function() {
    const style = {
      position: 'absolute',
      width: 50,
      height: 50,
      backgroundColor: 'lightblue',
      left: this.getTweeningValue('left'), // Retrieve the current tweening value
      cursor: 'pointer',
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      color: 'white'
    };
    return (
      <div style={style} onClick={this.handleClick}>
        Click Me
      </div>
    );
  }
});

// This code needs an HTML file with <div id="root"></div> and
// older versions of React/ReactDOM (e.g., v15) to run successfully.
// For example, in an HTML file with script tags for React, ReactDOM, and this example:
// ReactDOM.render(<App />, document.getElementById('root'));

view raw JSON →