Created
January 19, 2023 14:19
-
-
Save nicolasblanco/cdd7968079f3e79037359949c60bd38c 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 MyTwitterWeb.CounterLive do | |
use MyTwitterWeb, :live_view | |
def render(assigns) do | |
~H""" | |
<div> | |
<.button phx-click="dec">-</.button> | |
<%= @counter %> | |
<.button phx-click="inc">+</.button> | |
</div> | |
""" | |
end | |
def mount(_params, _session, socket) do | |
socket = | |
socket | |
|> assign(:counter, 10) | |
{:ok, socket} | |
end | |
def handle_event("dec", _, socket) do | |
{:noreply, update(socket, :counter, fn count -> count - 1 end)} | |
end | |
def handle_event("inc", _, socket) do | |
{:noreply, update(socket, :counter, fn count -> count + 1 end)} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment