def METHOD_NAME(grid_size, block_scale, set_game_state):
    # we `use_ref` here to capture the latest direction press without any delay
    direction = reactpy.hooks.use_ref(Direction.ArrowRight.value)
    # capture the last direction of travel that was rendered
    last_direction = direction.current
    snake, set_snake = reactpy.hooks.use_state(
        [(grid_size // 2 - 1, grid_size // 2 - 1)]
    )
    food, set_food = use_snake_food(grid_size, snake)
    grid = create_grid(grid_size, block_scale)
    @reactpy.event(prevent_default=True)
    def on_direction_change(event):
        if hasattr(Direction, event["key"]):
            maybe_new_direction = Direction[event["key"]].value
            direction_vector_sum = tuple(
                map(sum, zip(last_direction, maybe_new_direction))
            )
            if direction_vector_sum != (0, 0):
                direction.current = maybe_new_direction
    grid_wrapper = reactpy.html.div({"on_key_down": on_direction_change}, grid)
    assign_grid_block_color(grid, food, "blue")
    for location in snake:
        assign_grid_block_color(grid, location, "white")
    new_game_state = None
    if snake[-1] in snake[:-1]:
        assign_grid_block_color(grid, snake[-1], "red")
        new_game_state = GameState.lost
    elif len(snake) == grid_size**2:
        assign_grid_block_color(grid, snake[-1], "yellow")
        new_game_state = GameState.won
    interval = use_interval(0.5)
    @reactpy.hooks.use_effect
    async def animate():
        if new_game_state is not None:
            await asyncio.sleep(1)
            set_game_state(new_game_state)
            return
        await interval
        new_snake_head = (
            # grid wraps due to mod op here
            (snake[-1][0] + direction.current[0]) % grid_size,
            (snake[-1][1] + direction.current[1]) % grid_size,
        )
        if snake[-1] == food:
            set_food()
            new_snake = [*snake, new_snake_head]
        else:
            new_snake = snake[1:] + [new_snake_head]
        set_snake(new_snake)
    return grid_wrapper