Last active
June 16, 2021 11:03
-
-
Save SysCall97/84d5f0fd0224c8145a1c5c87cea91688 to your computer and use it in GitHub Desktop.
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
type props = { | |
callback: (a: string) => void; | |
} | |
const Child: React.FC<props> = ({callback}) => { | |
const [value, setVlaue] = useState<number>(0); | |
const isEven = () => { | |
let i = 0; | |
// this while loop is to mock a costly operation | |
while(i<1000000000) i++; | |
callback('isEven called'); | |
return value % 2 === 0; | |
} | |
return ( | |
<div> | |
{ | |
isEven() ? 'even': 'odd' | |
} | |
<button onClick={() => setVlaue(prev => prev + 1)}>Add one</button> | |
</div> | |
); | |
}; | |
export default React.memo(Child); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment