Kinsua

Kinsua

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.

Showing Posts 1 to 8

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
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.

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.

LostKobrakai

LostKobrakai

Nothing got merged there. LiveComponents as well as function components are a feature of phoenix_live_view and always have been. But the point about LiveComponents having existed for longer than function components does still stand. If things would’ve been the other way round things would certainly look different.

D4no0

D4no0

Hmm, I always thought that functional components come from classical phoenix and not liveview as they have nothing in common with what liveview does, but it seems you are right.

LostKobrakai

LostKobrakai

They need to be in live view because change tracking is a concept of live view, which heex integrates with.

D4no0

D4no0

It’s pretty strange that heex is still part of liveview. So what, you can’t use heex templates in a classic phoenix project without adding liveview as dependency?

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews