Skip to content

Confused with usage of Alpine.data vs Alpine.directive #4460

Answered by SimoTod
dotfrag asked this question in 1. Help
Discussion options

You must be logged in to vote

I would probably still model it as a directive. The boolean itself could come from somewhere else (like x-show) or if it's not relevant externally, you can bind an internal state (see the ui folder).

Alpine.data is meant to define data, not behaviours. However, as you said, you can probably achieve stuff by using init, if that comes easier for you, you should just use whatever makes you more productive.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@SimoTod
Comment options

SimoTod Dec 1, 2024
Collaborator

@dotfrag
Comment options

@SimoTod
Comment options

SimoTod Dec 2, 2024
Collaborator

Answer selected by dotfrag
@dotfrag
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants