Created
September 4, 2019 06:50
-
-
Save beardlessman/20df1952da3b233805f9fffe45665e23 to your computer and use it in GitHub Desktop.
react hook example, flow
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
//@flow | |
import React, { useState, useEffect } from 'react'; | |
type IProps = { | |
initial?: number, | |
}; | |
export default function HookExample({ initial = 0 }: IProps) { | |
const [fuckingCount, setFuckingCount] = useState(initial); | |
const [kek, setKek] = useState('kek'); | |
useEffect(() => { | |
document.title = `You clicked ${fuckingCount} times. ${kek}?`; | |
return () => console.log('UNMOUNT HookExample', kek); // выполнится перед unmount компонента | |
}, [kek]); // если изменилось хотя бы одна сущность из массива -- выполняем эффект | |
return ( | |
<div> | |
<p>You clicked {fuckingCount} fucking times</p> | |
<button onClick={() => setFuckingCount(fuckingCount + 1)}>Click me</button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment