useEffect with Condition - React Js
App.js:
import React, {useEffect, useState} from "react";
import './App.css'
import Student from "./Components/Student";
function App()
{
const [data, setData]=useState(10)
const [count, setCount]=useState(100)
return(
<div className="App">
<Student count={count} data={data}/>
<button onClick={()=>setCount(count+1)}>Update Count</button>
<button onClick={()=>setData(data+1)}>Update Data</button>
</div>
)
}
export default App;
----------------------
Student.js:
import React,{useEffect} from "react";
function Student(props)
{
useEffect(()=>{
alert("Count is :"+props.count)
}, [props.count])
return(
<div className="App">
<h1>count props: {props.count}</h1>
<h1>data props: {props.data}</h1>
</div>
)
}
export default Student;
Comments
Post a Comment