I have been in arguments with programmers that mixing elements with animations and react is very bad practice, and that all animations should be in a style sheet because that is something presentational that is only concerned with CSS.
However, I have also seen a great number of libraries using elements like VelocityComponent
or ReactCSSTransitionGroup
.
I wanted to use VelocityComponent
just for the ability to trigger callbacks on animations being completed/initiated, but I am not sure if this is considered good practice.
class Sidebar extends Component {
static propTypes = {
open: PropTypes.func,
onRequestChange: PropTypes.func,
onRequestComplete: PropTypes.func,
isOpen: PropTypes.bool.isRequired,
};
render() {
return (<div className={styles.sidebar}>
<VelocityComponent
duration={200}
animation={{ opacity: this.props.isOpen ? 1 : 0 }}
complete={() => this.props.onRequestComplete(this.props.isOpen)}
>
{this.props.children}
</VelocityComponent>
</div>);
}
}
An example use case for this would be to load some async request AFTER the sidebar is open to ensure the animation runs smoothly.
So, is it bad practice to include this inline?