Created
October 25, 2020 16:41
-
-
Save misss-popcorn/5cbde78fb4d8d5301631bf32f80909ca 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
import React, {useState, useEffect} from "react"; | |
export function UseEffectFunc() { | |
const [count, setCount] = useState(0); | |
useEffect(() => { | |
const interval = setInterval(() => { | |
setCount(count => count + 1); | |
}, 1000); | |
return () => { | |
clearInterval(interval); | |
}; | |
}, [count]); | |
return ( | |
<span className="Right"> | |
<p>Function Component</p> | |
<p>{count}</p> | |
</span> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment