How to Create Nested LiveView Components

From ElixirBlocks
Jump to: navigation, search

This example demonstrates a nested LiveView component.


defmodule AppxWeb.SandboxLive do
   use AppxWeb, :live_view  
   import MyComponent
   def mount(_params, _session, socket)  do
	 {:ok, socket}  
   end
   def render(assigns) do
	   ~H"""
	      Hello World! YAY
	     <MyComponent.greet name="Jane" />
	   """ 
   end
end

defmodule MyComponent do
   use Phoenix.Component

   def greet(assigns) do
	   ~H"""
	     <p>Hello, <%= @name %>!</p>
	   """ 
   end
end