Skip to content

Instantly share code, notes, and snippets.

@9oelM
Created October 3, 2019 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 9oelM/da3f3c6a7e843c27bbcc7c744e007137 to your computer and use it in GitHub Desktop.
Save 9oelM/da3f3c6a7e843c27bbcc7c744e007137 to your computer and use it in GitHub Desktop.
import React, { useState } from 'react';
const Child1 = () => {
console.log('Child1 rendered')
return <div style = {{border: '1px solid red', padding: '30px'}}>
Child1
</div>
}
const Child2 = () => {
console.log('Child2 rendered')
return <div style = {{border: '1px solid red', padding: '30px'}}>
Child2
</div>
}
const Parent = () => {
console.log('Parent rendered')
let [count, setCount] = useState(0)
const handleMouseEnter = () => setCount(prevCount => prevCount + 1)
return <div onMouseEnter={handleMouseEnter} style = {{border: '1px solid black', padding: '50px'}}>
Parent. Count: {count}
<Child1/>
<Child2/>
</div>
}
export default Parent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment