wecode.ex
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 WecodeWeb.FirstLive do | |
use WecodeWeb, :live_view | |
def mount(_params, _session, socket) do | |
{:ok, socket |> assign(:name, "Shuaib")} | |
end | |
def render(assigns) do | |
~H""" | |
<h1> <%= @name %> </h1> | |
<button phx-click="click" phx-value-sex="female"> Click me </button> | |
""" | |
end | |
@impl true | |
def handle_event("click", %{"sex" => sex}, socket) do | |
IO.inspect(sex, label: "sex") | |
send(self(),"msg") | |
{:noreply, socket |> assign(:name, "Hakeem")} | |
end | |
@impl true | |
def handle_info("msg", socket) do | |
IO.inspect("I GOT A MESSAGE") | |
{:noreply, socket} | |
end | |
def terminate(reason, socket) do | |
IO.inspect(reason, label: "reason") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment