我有一个反应应用程序,我正在使用包中的<Transition>
组件react-transition-group
在创建和销毁组件时创建过渡动画。我在循环中设置了in 道具。但是,当组件即将被销毁时componentWillMount
,我似乎无法弄清楚如何恢复in 道具。文档并没有真正说明退出过渡
这是我的代码:
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>
)
}
}