1. Component State & useState
While props allow parents to pass data in, state holds private, local component data that can change over time in response to user actions.
⊞Code Example
import React, { useState } from 'react';
export default function InteractiveCounter() {
const [count, setCount] = useState(0);
const [theme, setTheme] = useState("dark");
return (
<div style={{ padding: '20px', background: theme === 'dark' ? '#17181c' : '#fff' }}>
<h3 style={{ color: '#04AA6D' }}>Current Count: {count}</h3>
<div style={{ display: 'flex', gap: '8px' }}>
<button onClick={() => setCount(prev => prev + 1)}>Increment (+)</button>
<button onClick={() => setCount(prev => prev - 1)}>Decrement (-)</button>
<button onClick={() => setCount(0)}>Reset</button>
</div>
</div>
);
}
