async def _process_event(
        self,
        handler: EventHandler,
        state: BaseState | StateProxy,
        payload: builtins.dict,
    ) -> AsyncIterator[StateUpdate]:
        """Process event.

        Args:
            handler: EventHandler to process.
            state: State to process the handler.
            payload: The event payload.

        Yields:
            StateUpdate object

        Raises:
            ValueError: If a string value is received for an int or float type and cannot be converted.
        """
        from reflex.utils import telemetry

        # Get the function to process the event.
        fn = functools.partial(handler.fn, state)

        try:
            type_hints = typing.get_type_hints(handler.fn)
        except Exception:
            type_hints = {}

        for arg, value in list(payload.items()):
            hinted_args = type_hints.get(arg, Any)
            if hinted_args is Any:
                continue
            if is_union(hinted_args):
                if value is None:
                    continue
                hinted_args = value_inside_optional(hinted_args)
            if (
                isinstance(value, dict)
                and inspect.isclass(hinted_args)
                and not types.is_generic_alias(hinted_args)  # py3.10
            ):
                if issubclass(hinted_args, Model):
                    # Remove non-fields from the payload
                    payload[arg] = hinted_args(
                        **{
                            key: value
                            for key, value in value.items()
                            if key in hinted_args.__fields__
                        }
                    )
                elif dataclasses.is_dataclass(hinted_args) or issubclass(
                    hinted_args, (Base, BaseModelV1, BaseModelV2)
                ):
                    payload[arg] = hinted_args(**value)
            elif isinstance(value, list) and (hinted_args is set or hinted_args is set):
                payload[arg] = set(value)
            elif isinstance(value, list) and (
                hinted_args is tuple or hinted_args is tuple
            ):
                payload[arg] = tuple(value)
            elif isinstance(value, str) and (
                hinted_args is int or hinted_args is float
            ):
                try:
                    payload[arg] = hinted_args(value)
                except ValueError:
                    msg = f"Received a string value ({value}) for {arg} but expected a {hinted_args}"
                    raise ValueError(msg) from None
                else:
                    console.warn(
                        f"Received a string value ({value}) for {arg} but expected a {hinted_args}. A simple conversion was successful."
                    )

        # Wrap the function in a try/except block.
        try:
            # Handle async functions.
            if asyncio.iscoroutinefunction(fn.func):
                events = await fn(**payload)

            # Handle regular functions.
            else:
                events = fn(**payload)
            # Handle async generators.
            if inspect.isasyncgen(events):
                async for event in events:
                    yield await state._as_state_update(handler, event, final=False)
                yield await state._as_state_update(handler, events=None, final=True)

            # Handle regular generators.
            elif inspect.isgenerator(events):
                try:
                    while True:
                        yield await state._as_state_update(
                            handler, next(events), final=False
                        )
                except StopIteration as si:
                    # the "return" value of the generator is not available
                    # in the loop, we must catch StopIteration to access it
                    if si.value is not None:
                        yield await state._as_state_update(
                            handler, si.value, final=False
                        )
                yield await state._as_state_update(handler, events=None, final=True)

            # Handle regular event chains.
            else:
                yield await state._as_state_update(handler, events, final=True)

        # If an error occurs, throw a window alert.
        except Exception as ex:
            telemetry.send_error(ex, context="backend")

            event_specs = (
                prerequisites.get_and_validate_app().app.backend_exception_handler(ex)
            )

            yield await state._as_state_update(
                handler,
                event_specs,
                final=True,
            )
Process event.

        Args:
            handler: EventHandler to process.
            state: State to process the handler.
            payload: The event payload.

        Yields:
            StateUpdate object

        Raises:
            ValueError: If a string value is received for an int or float type and cannot be converted.
        
reflex/state.py