Skip to content

Instantly share code, notes, and snippets.

@shubie
Last active November 22, 2019 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shubie/85ed0b35656a438909875f445abf213d to your computer and use it in GitHub Desktop.
Save shubie/85ed0b35656a438909875f445abf213d to your computer and use it in GitHub Desktop.
defmodule NoReactWeb.StatefulComponentLive do
use Phoenix.LiveView
def render(assigns) do
~L"""
<div>
Seconds <%= @seconds %>
</div>
"""
end
def mount(_session, socket) do
if connected?(socket), do: :timer.send_interval(1000, self(), :change)
{:ok, assign(socket, seconds: 1)}
end
def handle_info(:change, socket) do
{:noreply, assign(socket, seconds: socket.assigns.seconds + 1)}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment