Use effect instead of boolean flag