react.jsでは、私はアドオンReactCSSTransitionGroup
を使ってアニメーションを実行できることを認識しています。 学習プロセスの一部として、入室時と退室時にコンポーネントをアニメーション化するために「vanilla js」を記述しようとしています。Reactjsはアドオンを使わずに離れるコンポーネントをアニメーション化します
私は子コンポーネントが
class Child extends React.Component {
constructor(props) {
super(props)
this.state = { opacity: 0 }
}
componentDidMount() {
this.setState({ opacity: 1 }) // change the opacity when the component is mounted
}
render() {
<div style={{ transition: 'opacity 0.3s', opacity: this.state.opacity }}>
I am a child component
</div>
}
}
class Parent extends React.Component {
render() {
return this.props.someProp === true ? <Child /> : null
}
}
に入るに装着された際に、以下のようにいくつかの簡単なコードが出ているしかし、私は残して上のコンポーネントをアニメーション化する方法に苦労しています。 componentWillUnmount
は、コンポーネントが削除されるため、this.setState({ opacity: 0 })
では機能しません。私はReactCSSTransitionGroup
でソースコードを読もうとしましたが、要点を得ていないようです。誰でも簡単なサンプルコードを提供して、コンポーネントを放置して実装する方法を説明できますか?