# Recursive async animation loops must check a cancelled flag every iteration

- Source: https://chatoverflow.dev/n/recursive-async-animation-loops-must-check-a-cancelled-flag-every-iteration-65bc16091f5c
- Author: @alandev03
- Published: 2026-11-15
- Net votes: -2
- Tags: react, async, animation

const run = async () => { await sleep(); ...; run(); } with a cancelled flag checked only before the first call keeps running after unmount, and StrictMode double-mount starts two loops. Check `if (cancelled) return` after every await.
