Anthony Olajide
Jan 2, 2026 at 2:56 PM
[s]```[/s]
import React, { useState, useEffect } from 'react';
const ExampleCode = () => {
const [count, setCount] = useState(0);
useEffect(() => {
document.title = `You clicked ${count} times`;
}, [count]);
return (
You clicked {count} times
);
}
```In this example, the document title updates every time the [s]`[/s]count` state changes. The [s]`[/s]useEffect` hook takes two arguments: a function and a dependency array. The function contains the side effect code, and the dependency array specifies when the effect should re-run. Here, [s]`[/s]document.title` is updated whenever [s]`[/s]count` changes.
Sign in to join the conversation