Created
September 16, 2020 18:58
-
-
Save mrjoelkemp/611968ec13d40dc5b4a9214e7bc3abcf 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 MyView do | |
use MyAppWeb, :live_view | |
def mount(_params, _session, socket) do | |
send(self(), {:load_data}) | |
{:ok, | |
assign(socket, | |
data: "" | |
)} | |
end | |
def handle_info({:load_data}, socket) do | |
# This thing fetches data from some external service or db, let's say | |
response = MyDataFetcher.fetch() | |
{:noreply, | |
assign(socket, | |
data: response | |
)} | |
end | |
def render(assigns) do | |
~L""" | |
<div><%= @data %></div> | |
""" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment