Problem Statement
Create a simple React Hooks example with useState and useEffect.
Explanation
useState manages component state; useEffect runs side effects after render. For example, updating the document title when count changes.
Code Solution
SolutionRead Only
function Counter(){
const [count,setCount]=useState(0);
useEffect(()=>{document.title=`Count ${count}`;},[count]);
return <button onClick={()=>setCount(count+1)}>Add</button>;
}Practice Sets
This question appears in the following practice sets: