I am adding runnable code snippets below. see the difference First one is React.PureComponent version
class App extends React.PureComponent {
render() {
console.log('re-render')
return (
<div>
<span>I am parent</span>
{this.props.children}
</div>
)
}
}
ReactDOM.render(
<App>
<div>
I am the child
</div>
</App>,
document.getElementById('app')
)
//setTimeout(render, 1000)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="app"></div>
class App extends React.Component {
render() {
console.log('re-render')
return (
<div>
<span>I am parent</span>
{this.props.children}
</div>
)
}
}
ReactDOM.render(
<App>
<div>
I am the child
</div>
</App>,
document.getElementById('app')
)
//setTimeout(render, 1000)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="app"></div>
Why the second one runs successfully, but not the first one?? I tried exploring for the reason, but didnot find any good reason