Skip to content

Use hooks instead of LiveComponents #2026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2025
Merged

Conversation

joshk
Copy link
Collaborator

@joshk joshk commented Apr 7, 2025

When I built the tabs for the Device page, and then used a similar pattern for the Deployment page, I quickly learnt that LiveComponents have a lot of quicks which lead to confusing code and duplicated state between the parent and child component.

For example, LiveComponents can't subscribe to topic, listen for pubsub messages, or respond to timer events.

I recently discovered a better path forward which uses LiveView hooks : https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#attach_hook/4

I've created some reusable code for implementing the same pattern with the Deployment page, and the upcoming Org pages.

@joshk joshk force-pushed the move-away-from-live-components branch from 9e475d9 to b41b77c Compare April 7, 2025 06:42
@joshk joshk force-pushed the move-away-from-live-components branch from b41b77c to f5a4693 Compare April 7, 2025 09:13
Copy link
Contributor

@nshoes nshoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, a couple of thoughts

@joshk joshk force-pushed the move-away-from-live-components branch from 7a86e46 to dac5d7b Compare April 8, 2025 02:48
@joshk joshk force-pushed the move-away-from-live-components branch from dac5d7b to c9123c1 Compare April 8, 2025 03:02
@joshk joshk requested a review from nshoes April 8, 2025 04:17
@nshoes nshoes merged commit bfdbba9 into main Apr 8, 2025
2 checks passed
@nshoes nshoes deleted the move-away-from-live-components branch April 8, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants