Skip to content

Instantly share code, notes, and snippets.

@mrjoelkemp
Created September 16, 2020 18:58
Show Gist options
  • Save mrjoelkemp/611968ec13d40dc5b4a9214e7bc3abcf to your computer and use it in GitHub Desktop.
Save mrjoelkemp/611968ec13d40dc5b4a9214e7bc3abcf to your computer and use it in GitHub Desktop.
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