Kinsua

Kinsua

I don't understand the difference between Phoenix.Component and Phoenix.LiveComponent

Both will change the @something value when it’s changed in real time. Both are “live”.

So what is the difference?

Isn’t the naming a bit unfortunate? Because the normal components change in the live process as well in real time.

This part from docs is super confusing, I don’t know when it’s about compoents and when about liveComponents:

Components have their own mount/3 and handle_event/3 callbacks, as well as their own state with change tracking support. Components are also lightweight as they “run” in the same process as the parent LiveView. However, this means an error in a component would cause the whole view to fail to render. See Phoenix.LiveComponent for a complete rundown on components.

Most Liked

sodapopcan

sodapopcan

I agree the docs wording is confusing. Under one section it talks about both function components and live components. At one point it starts referring to live components as simply “components.” While it can be inferred from context, I found myself thinking it’s referring back to function components before going on to talk about live components.

I can work on a PR to clarify a little.

APB9785

APB9785

Creator of ECSx

LiveComponent stores mutable state similar to LiveView/GenServer. You can change the state with events that include phx-target={@myself} and defining event handlers in the LiveComponent module.

Phoenix.Component holds no state. It receives inputs, but cannot change those inputs. It is purely “functional”. These functional components cannot be targets of events, and cannot define the event handler logic which would be required to change the state.

Assuming your app has some state:

  • LiveComponent will handle (store and update) the state without its parent needing to know what’s going on
  • Phoenix.Component will require the parent to manage the state, and the component doesn’t have any idea about how the state changes
D4no0

D4no0

The documentation is mixed because live components used to be located in liveview documentation, there were no functional components back then.

I guess when liveview was added officially to the framework as a default, the documentations got merged and it’s a mess even to this day, as you don’t understand where one feature ends and another starts.

Last Post!

steffend

steffend

Phoenix Core Team

This is correct. You cannot use HEEx without depending on LiveView. HEEx directly integrates into the LiveView custom EEx engine and is intertwined with LiveView’s change tracking. Trying to separate this would be a lot of work and probably not worth the effort.

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement