Yielding Updates
A regular event handler will send a StateUpdate when it has finished running. This works fine for basic event, but sometimes we need more complex logic. To update the UI multiple times in an event handler, we can yield when we want to send an update.
To do so, we can use the Python keyword yield. For every yield inside the function, a StateUpdate will be sent to the frontend with the changes up to this point in the execution of the event handler.
A foreground event handler that raises an exception or is cancelled keeps the state changes it made, as long as it still holds the state lock. This includes updates already yielded to the frontend before another invocation of an @rx.event(supersedes=True) handler cancels it. Changes made after the handler's last yield are sent to the frontend when the handler raises or is cancelled.
This example below shows how to yield 100 updates to the UI.
Here is another example of yielding multiple updates with a loading icon.
Yielding Other Events
Events can also yield other events. This is useful when you want to chain events together. To do this, you can yield the event handler function itself.