Web Development React.js Subjective
Sep 28, 2025

What is the useState hook and how is it used?

Detailed Explanation

useState is a React hook that allows functional components to have state. It returns an array with the current state value and a function to update it.

import { useState } from "react";

function Counter() {
  const [count, setCount] = useState(0);
  
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>
        Increment
      </button>
    </div>
  );
}
Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback