I have this code for unmounting and remounting elements:
import React, { Component } from 'react';
import './App.css';
import Header from './Header';
import Bottom1 from './Bottom1';
import Bottom2 from './Bottom2';
class App extends Component {
constructor(){
super();
this.state={
playWindow: true
}
this.update = this.update.bind(this);
}
update(){
const newState = this.state.playWindow? false : true;
this.setState({playWindow: newState});
}
render() {
return (
<div className="App">
<Header update={this.update}/>
{this.state.playWindow? <Bottom1/> : <Bottom2/> }
</div>
);
}
}
export default App;
When I do the action, the components are exchanged. The problem is that there is no transition, the toggle fells rough. How do I add an animation, like one fading out, and then the other fading in?
You can animate components with react-transition-group. Check the docs here.
Example from the official docs: