Reputation: 313
//state for time
let [time,setTime] = useState("11:15")
//setTime when change occurs in input
let TimeChange = (t) =>{
console.log('recieved time is:', t)
setTime(t)
console.log(time,': is set')
}
//using TimePicker inside return
<TimePicker
onChange={TimeChange}
value={time}
/>
what am expecting in console is:
recieved time is 12:00
12:00 is set
what am getting in the console is:
recieved time is: 12:00
11:15 : is set (// initial time)
recieved time is: 12:30 (// this is the next input i gave)
12:00 : is set (// first update)
My question is why its not updating first time itself?
Upvotes: 0
Views: 64
Reputation: 4518
Updating the state using the useState hook does not immediately reflect and update the state but will trigger a re-render.
Upvotes: 1