# Liveview - rerendering nonstop (keeps making api request)

**URL:** <https://forum.elixirforum.com/t/liveview-rerendering-nonstop-keeps-making-api-request/31215>\
**Category:** Questions\
**Tags:** phoenix, apis, phoenix-liveview\
**Created:** [May 3, 2020, 10:25pm UTC](https://forum.elixirforum.com/t/liveview-rerendering-nonstop-keeps-making-api-request/31215 "2020-05-03T22:25:43Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jhefreyzz](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhefreyzz/32/18075_2.png) [@jhefreyzz](https://forum.elixirforum.com/u/jhefreyzz)\
**Post date:** [May 4, 2020, 12:19am UTC](https://forum.elixirforum.com/t/liveview-rerendering-nonstop-keeps-making-api-request/31215/2 "2020-05-04T00:19:05Z")

</div>

Hi, have you tried using [connected?](https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html?#connected?/1) function since liveview is mounted twice.

```elixir
def mount(params, _session, socket) do
  if connected?(socket) do
    case Reddit.request_token(params["code"]) do
     "invalid_grant" ->
       {:ok,  
         socket
         |> put_flash(:error, "Token Invalid!")
         |> redirect(to: "/")
       }

      token ->
       {:ok, response} = Reddit.get_user_saves(token)
       {:ok, assign(socket, :saves, response.body)}
    end
  end
end

```

---

_[View the full topic](https://forum.elixirforum.com/t/liveview-rerendering-nonstop-keeps-making-api-request/31215)._
