Skip to content

Instantly share code, notes, and snippets.

@SysCall97
Last active June 16, 2021 11:03
Show Gist options
  • Save SysCall97/84d5f0fd0224c8145a1c5c87cea91688 to your computer and use it in GitHub Desktop.
Save SysCall97/84d5f0fd0224c8145a1c5c87cea91688 to your computer and use it in GitHub Desktop.
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