Problem Statement
How do you handle state in class vs functional components?
Explanation
In class components, state is managed with this.state and updated using setState(). In functional components, state is handled with the useState() Hook. Both trigger re-renders when the state changes.
Code Solution
SolutionRead Only
// Functional
const [count, setCount] = useState(0);
// Class
this.state = { count: 0 };
this.setState({ count: this.state.count + 1 });