How State Works in React – Explained with Code Examples