Hook and useState in React

 


import './App.css'
import React ,{useStatefrom "react";



function App(){
//setInterval(updateTime,1000) //1000 is sec
//this is a function by javascript

  const now = new Date().toLocaleTimeString();
  const [timesetTime] = useState(now); // first wla variable and 2nd wala function
ever time useState me kuch hona chiya phela

function updateTime(){
  const newTime = new Date().toLocaleTimeString(); //variable 
  setTime(newTime);
}

return(
  <div className = "container">
  <h1>{time}</h1>
  <button onClick={updateTime}>GetTime</button>
</div>
)

}
    
   

export default App;

/////////////////////////////////////////////////////////////////////////////////////

Step 1 :- we have to Import useSate from react

step 2 ;- creat function and under which create another function

create aka variable const and [] first wla hoga ake variable and 2nd wala mae function
hoga






















Comments

Popular posts from this blog

Props and pass data from object list

Changing complex state in React (react forms)

filer method()