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
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
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
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
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.
Popular in Questions
Other popular topics
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









