- Create Components folder under src folder
- Add UseEffectEXP1.js file and add below Code
import React, { useState, useEffect } from "react";
function UseEffectEXP1() {
const [name, setname] = useState("");
useEffect(() => {
console.log("useEffect");
setname("adi");
document.title = "Use Effect EXP1";
}, []);
return (
<div>
<div>Use Effect EXP1</div>
<div>{name}</div>
</div>
);
}
export default UseEffectEXP1;
- Open index.js file and update code as below
import React from "react";
import ReactDOM from "react-dom";
import UseEffectEXP1 from "./components/UseEffectEXP1";
function App() {
return (
<div className="App">
<UseEffectEXP1 />
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
No comments:
Post a Comment