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

Useeffect Hooks In React.Js






Purpose





Example




import React, { useState, useEffect  } from 'react';
import ReactDOM from 'react-dom';

const Home = () => {

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

    useEffect(() => {
        alert("this is invoked when the content is rendered");
    });

    const handleClick = () => {
        setName('Gyansangrah');
    }

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


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







Output


Picture showing the output of useEffect hooks in react.js
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, November 7, 2021

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250