Skip to content

Instantly share code, notes, and snippets.

@mohammed-io
Created December 14, 2020 20:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohammed-io/676c1c150b9558c990f61c1f477dae2c to your computer and use it in GitHub Desktop.
Save mohammed-io/676c1c150b9558c990f61c1f477dae2c to your computer and use it in GitHub Desktop.
For Gokhan
'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