Created
December 14, 2020 20:38
-
-
Save mohammed-io/676c1c150b9558c990f61c1f477dae2c to your computer and use it in GitHub Desktop.
For Gokhan
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
'use strict' | |
const { useState, useCallback, useEffect } = React | |
const JobTitle = React.memo(function JobTitle(props) { | |
console.log('rendered') | |
return <h1>Hello, {props.name} {props.age}</h1> | |
}) | |
function Greet({name, age, title, email}) { | |
const [count, setCount] = useState(0) | |
const [toggle,setToggle] = useState(false) | |
const increment = useCallback(() => { | |
setCount(count => count + 1) | |
}, [count]) | |
useEffect(() => { | |
console.log('effect') | |
setToggle(count % 4 === 0) | |
}, [Math.floor(count / 2)]) | |
return ( | |
<div> | |
<JobTitle name={name} age={age}></JobTitle> | |
<h3>{title} {count}</h3> | |
<i>{email}</i> | |
<div> | |
{toggle ? 'true' : 'false'} | |
</div> | |
<button onClick={increment}>+</button> | |
</div> | |
) | |
} | |
ReactDOM.render(<Greet name="Gokhan" age="25" email="gokhan@hey.com"/>, document.querySelector("#app")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment