Skip to content

Instantly share code, notes, and snippets.

@misss-popcorn
Created October 25, 2020 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misss-popcorn/5cbde78fb4d8d5301631bf32f80909ca to your computer and use it in GitHub Desktop.
Save misss-popcorn/5cbde78fb4d8d5301631bf32f80909ca to your computer and use it in GitHub Desktop.
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