setInterval does not use updated values of useState variables