Explain Effect Hook with an example?

Answer

If an action is performed on a webpage, an Effect Hook may be used to transfer a side effect to another part of the DOM.
The example below updates the document title of the webpage when a button is clicked:
function Effect() {
const [car, setcar] = useState('Ferrari');
useEffect(() => {

document.title = `My favorite car is ${car}`;
});

return (
<div>
<p>My favorite car is {car}</p>
<button onClick={() => setcar('McLaren')}>
Not this one?
</button>
</div>
);
}

All react js Questions

Ask your interview questions on react-js

Write Your comment or Questions if you want the answers on react-js from react-js Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---