Articles → REACT.JS → Usestate Hooks In React.Js

Usestate Hooks In React.Js






Purpose





Example




import ReactDOM from 'react-dom'
import { useState } from 'react';


const Home = () => {
    
    const [name, setName] = useState('Gyan');
    
    const handleClick = () => {
        setName('Gyansangrah');        
    }

    return (
        <div>
            <p>{name}</p>
            <button onClick={handleClick}>Click me</button>
        </div>
    );
}

ReactDOM.render(<Home />, document.getElementById('root'));






const [name, setName] = useState('Gyan');





Output


Picture showing the output of the useState hooks in React.js
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, September 3, 2021

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250