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
Click to Enlarge