Last active
November 22, 2019 13:39
-
-
Save shubie/85ed0b35656a438909875f445abf213d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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