function Example() { const [count, setCount] = React.useState(0); React.useEffect(() => { // similar to componentDidMount() & componentDidUpdate() document.title = `You clicked ${count} times`; return ()=>{ // similar to componentWillUnmount() with []; optional alert("Sorry to see you go!"); } },[]); // prevents unintentional alert() call since no change in array;, optional return (
You clicked {count} times