I'm doing something weird in React, and it makes me wonder if there's a better pattern. Basically, I need a button click handler to be async, run a for loop that awaits multiple promises, and in-between each promise performs a state update. It's working, but if the component unmounts while the async handler is running, it will try to update state on an unmounted component. Usually, I see people prevent this when they're declaring an async function inside a useEffect by setting a boolean flag and flipping the value on the cleanup function of the useEffect. When the promise completes, it checks the flag. Since it's defined in the closure, it has access to updates to it. In my case, this async event handler is *not* declared inside a useEffect, so I can't do that. Should I just use a ref and set the ref on component unmount? Anyone have any better ideas?