use requestAnimationFrame when setting states