Partials vs LiveComponents

I’m curious on the distinction between partials and LiveComponents. The more I work with LiveComponents the less I feel the need to render partials in a LiveView, but I’m wondering if I’m missing something.

1 Like

I think the historical context is that within the current landscape/zeitgeist of web development, the V in the traditional MVC pattern has shifted from a more Rails-esque partial templates rendering style for encapsulating reusable chunks of HTML to a more React-esque Component rendering style, especially as it became acceptable again to colocate code for content (HTML), styling (CSS), and behavior (JS).

From partials to ViewComponents: writing reusable front-end code in Rails - DEV Community
An Introduction to the ViewComponent Gem - Honeybadger Developer Blog

5 Likes

Ya, partials aren’t even required for Phoenix without LiveView anywhere, it’s components everywhere. There’s no need for partials in Phoenix anymore.

2 Likes

Just as a point of clarification, are you talking about function components vs. LiveView components?

In general if I was replacing a partial I’d be referring to a LiveView component due to the amount of complexity/state that the partial would likely have contained. But yeah whenever possible I’d use Phoenix.Component if I didn’t need to manage state.