import React, { useState, useEffect } from 'react';
import './App.css'
const App = () => {
const [cnt, setCnt] = useState(0)
const [tmp, setTmp] = useState('10')
useEffect(() => {
document.title = `${cnt}`
console.log("use effect called")
},[cnt])
// only run useEffect when cnt value changes, condition applied on cnt
return (
<div className="App">
<input type="text" onChange={(e) => {
setTmp(e.target.value)
console.log(e.target.value)
}} />
"text {tmp} "
<button onClick={() => setCnt(cnt + 1)}>Plus+</button>
{cnt}
</div>
);
}
export default App;
//useEffect runs after every render of component
sideeffect => any thing that reaches outside of component to do something
eg. n/w request
manual dom manipulation to modify other parts of dom
event Listener, timeout and interval
Comments
Post a Comment