Q1.

const [count, setCount]=useState(0)
useEffect(()=>{
	setCount(count + 1)
},[])

//Output: 1

Q2.

const [count, setCount]=useState(0)
useEffect(()=>{
	setCount(count + 1)
},[])
useEffect(()=>{
	setCount(count + 2)
},[])

Output:  you expect the output 3 but the actual output is 2.
Because react takes the initial state value 0 and not update value 1.

Q3.

Const [text, setText]=useState("kondeti")
Function handleClick(){
	setCount(text+"shivaji")
	setCount("shivaji")
}

Output: you expect the output kondeti Shivaji but the actual output is Shivaji.
Because the react takes the recent value.

Q4.


Const [count, setCount]=useState(0)
Function handleClick(){
	setCount(preState => preState +1)
	setCount(preState => preState +1)
}

Output :
2 - first click
4 - second click
Goes on.

Note: With every click, the count value is incremented by 2 because you have a setter function and you update the count value using the count's previous state. If you directly update the state variable with multiple setter functions, react performs batching. If you update the state variable through the previous state, react executes the asynchronous but synchronizes(one by one).

Q5.

const [count, setCount]=useState(0)
function handleClick(){
setCount(count +1 )
	SetTimeout (()=>{
	alert(count)
},1000)
}

Output : 0
Because SetTimeout forms a closure, it takes the initial value and I'd doesn't know the recent value(update).
Note: if you click again, the alert output is 1, because it takes the initial value of that particular time( what is the value of count while registering  the SetTimeout)
'
'
'
Goes on.

Q6.

Const [count, setCount]=useState(0)
useEffect(()=>{
	const id = setInterval(()=>{
  setCount(count + 1)
  },1000)
	return ()=> clearInterval(id)
},[])

useEffect(()=>{
	if(count ==10) {
		ClearInterval(id) //reference error because you can't access the id, it is not available within the scope.
  }
	setCount(count + 2)

},[count])

Output: reference error.

Q7.