Skip to content

Instantly share code, notes, and snippets.

@night-fury-rider
Last active March 23, 2021 03:18
Show Gist options
  • Save night-fury-rider/418f2cdf85caa1c9b0f45c29ed7db419 to your computer and use it in GitHub Desktop.
Save night-fury-rider/418f2cdf85caa1c9b0f45c29ed7db419 to your computer and use it in GitHub Desktop.
React Hook - useEffect
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