Last active
January 14, 2019 16:43
-
-
Save vzaidman/3659912d731607e7501fac5ac3b55633 to your computer and use it in GitHub Desktop.
react-lecture-why-did-you-render/01-the-demo
This file contains hidden or 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' | |
class ChildComponent extends Component { | |
componentDidMount() { | |
console.log('ChildComponent Component Did Mount') | |
} | |
componentWillUnmount() { | |
console.log('ChildComponent Un-mount :*(') | |
} | |
componentDidUpdate() { | |
console.log('ChildComponent Component Did Update') | |
} | |
render() { | |
console.log('ChildComponent Render') | |
return ( | |
<div> | |
ChildComponent | |
</div> | |
) | |
} | |
} | |
export default ChildComponent |
This file contains hidden or 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 ChildComponent from './ChildComponent' | |
import FatherComponent from './FatherComponent' | |
export default class Demo extends Component { | |
state = {counter: 0} | |
render() { | |
return ( | |
<div className="demo"> | |
<button onClick={ | |
() => this.setState({counter: this.state.counter + 1}) | |
}> | |
Increase Counter ({this.state.counter}) | |
</button> | |
<FatherComponent> | |
<ChildComponent/> | |
</FatherComponent> | |
</div> | |
); | |
} | |
} |
This file contains hidden or 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' | |
class FatherComponent extends Component { | |
componentDidMount() { | |
console.log('FatherComponent componentDidMount') | |
} | |
componentWillUnmount() { | |
console.log('FatherComponent Un-mount :*(') | |
} | |
componentDidUpdate() { | |
console.log('FatherComponent Component Did Update') | |
} | |
render() { | |
console.log('FatherComponent Render') | |
const {children} = this.props | |
return ( | |
<div style={{border: '1px solid white', padding: 5, position: 'relative'}} > | |
<span style={{fontSize: 16, position: 'absolute', top: -15, left: 0}}> | |
FatherComponent | |
</span> | |
{children} | |
</div> | |
) | |
} | |
} | |
export default FatherComponent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment