gistlib
index.tsximport React, { useState, useEffect } from 'react'; const MyComponent = () => { const [count, setCount] = useState(0); // useEffect hook to perform side effects in a functional component useEffect(() => { // code inside this block will execute after every render document.title = `You clicked ${count} times`; }, [count]); // dependency array ensures it only runs when count changes return ( <div> <p>You clicked {count} times</p> <button onClick={() => setCount(count + 1)}>Click me</button> </div> ); }; export default MyComponent; 618 chars21 lines
import React, { useState, useEffect } from 'react'; const MyComponent = () => { const [count, setCount] = useState(0); // useEffect hook to perform side effects in a functional component useEffect(() => { // code inside this block will execute after every render document.title = `You clicked ${count} times`; }, [count]); // dependency array ensures it only runs when count changes return ( <div> <p>You clicked {count} times</p> <button onClick={() => setCount(count + 1)}>Click me</button> </div> ); }; export default MyComponent;
gistlibby LogSnag