Last active
March 23, 2021 03:18
-
-
Save night-fury-rider/418f2cdf85caa1c9b0f45c29ed7db419 to your computer and use it in GitHub Desktop.
React Hook - useEffect
This file contains hidden or 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'; | |
function Example() { | |
const [count, setCount] = useState(0); | |
useEffect(() => { | |
document.title = `You clicked ${count} times`; | |
}, [count]); // Only re-run the effect if count changes | |
return ( | |
<button onClick={() => setCount(count + 1)}> Click me </button> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment