React Hooks: useState and useEffect

8 min read JAVASCRIPT 5 views

Managing State & Side Effects with Hooks

Hooks let functional components manage internal state and respond to lifecycle events without writing class components. useState handles local reactive state, while useEffect synchronizes with external systems like data fetching and document titles.

javascript Example
Run Code
import React, { useState, useEffect } from 'react';

export default function Counter() {
    const [count, setCount] = useState(0);

    useEffect(() => {
        document.title = `Clicked  times`;
    }, [count]);

    return (
        <div>
            <p>Current count: {count}</p>
            <button onClick={() => setCount(count + 1)}>Increment</button>
        </div>
    );
}

Related Tutorials