M
M
masambrero2016-12-08 12:09:18
css
masambrero, 2016-12-08 12:09:18

How to implement animation inside a React component?

Good afternoon
While learning React, I ran into an animation problem for individual parts of a component.
Subject - the following render occurs:
render () {
const number = (this.state.number)
return (
*some html*
{number}
*some html*
)
}
Accordingly, when the state changes, the content of the header changes. The question is - is it possible to somehow animate this change without moving it into a separate component?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2016-12-15
@masambrero

Use the react-motion lib.

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

<Motion style={{x: spring(this.state.open ? 400 : 0)}}>
          {({x}) =>
            <div className="demo0">
              <div className="demo0-block" style={{
                WebkitTransform: `translate3d(${x}px, 0, 0)`,
                transform: `translate3d(${x}px, 0, 0)`,
              }} />
            </div>
          }
        </Motion>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question