Last active
October 3, 2017 05:45
-
-
Save igorrmotta/36cbee9acc9f2d2360f28478ba1ff724 to your computer and use it in GitHub Desktop.
This snippet reproduces a bug with React@16 and react-transition-group. For some reason, the new reconciler algorithm of react removes the css effect when componentDidMount is fired. But anything that happens after that point, works.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import Transition, { ENTERING, ENTERED } from 'react-transition-group/Transition'; | |
import './App.css'; | |
const duration = 8000; | |
const fadeStyles = { | |
[ENTERING]: 'in', | |
[ENTERED]: 'in', | |
}; | |
const Fade = props => { | |
console.log('render Fade', props); | |
return ( | |
<Transition | |
{...props} | |
className="fade" | |
timeout={duration} | |
> | |
{status => { | |
console.log('status', status); | |
return ( | |
<div | |
style={{ backgroundColor: 'red', width: '600px', height: '600px' }} | |
className={`fade ${fadeStyles[status]}` || ''} | |
> | |
{props.children} | |
</div> | |
); | |
}} | |
</Transition> | |
); | |
}; | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
show: false | |
}; | |
} | |
componentDidMount() { | |
console.log('componentDidmount') | |
this.setState({ show: true }) | |
// setTimeout(() => { | |
// console.log('timedout') | |
// this.setState({show: true}) | |
// }, 0); | |
} | |
render() { | |
console.log('render', this.state.show); | |
return ( | |
<div> | |
<button onClick={() => this.setState({ show: !this.state.show })}> | |
Toggle | |
</button> | |
<Fade in={this.state.show} > | |
<h1>Hello world!</h1> | |
</Fade> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment