What is UseState ?
 The UseState is the hooks in React.js. It is the fundamental hook is allow to functional components to manage and update the internal state.It is a inbuilt function.Its add to state variables to functional components.
Syntax:
const[state,setState]=usestate(0)
Example:
import React, { useState } from 'react';
function Counter() {
  const [count, setCount] = useState(0); // Initialize count to 0
  const increment = () => {
    setCount(prevCount => prevCount + 1); // Update count based on previous state
  };
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={increment}>Increment</button>
    </div>
  );
}
export default Counter;
 

 
    
Top comments (0)