I have a react app and I'm using the <Transition>
component from the react-transition-group
package to create transition animations when the component is created and destroyed. I set the in prop in the componentWillMount
cycle. However, I can't seem to figure out how to revert the in prop back when the Component is about to be destroyed. The docs didn't really say much about the exit transition
Here is my code:
const defaultStyle = {
transition: `opacity 1000ms ease-in-out`,
opacity: 0,
padding: 20,
display: 'inline-block',
backgroundColor: '#8787d8'
};
const transitionStyles = {
entering: { opacity: 0 },
entered: { opacity: 1 },
exiting: { opacity: 1 },
exited: { opacity: 0 },
};
export default class Home extends Component {
constructor() {
super();
this.state = {
in: false
}
}
componentWillMount() {
const home = this;
// This: Works Perfectly
home.setState({ in: true });
}
componentWillUnmount() {
const home = this;
// This: Not so much
home.setState({ in: false });
}
render() {
return (
<Transition in={ this.state.in } timeout={ 0 }>
{(state) => (
<div className="page" style={{
...defaultStyle,
...transitionStyles[state]
}}>
I'm A fade Transition!
</div>
)}
</Transition>
)
}
}