Make x-data values or states, shareable amongst unrelated components by using a common Id #3772
Closed
timeax
started this conversation in
3. Feature Ideas
Replies: 1 comment 2 replies
-
I got you fam |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I don't know if that title made any sense but, consider the following HTML code
We are familiar with the outcome of clicking the button in both examples 1 and 2. However, my focus is on the second example, where the feature is intended to modify both the text in the h2 span element and the button text. The syntax for this change will resemble the following.
As the title implied, the id in
x-data.id
is the common id shared by both the button and h2 tags. And now, the changes should be seen in both elements when the button is clicked. The feature is inspired by React Fragments, which allows rendering child nodes without a wrapping element and preserving their state values if available.The above example shows a use case for which multiple states need to be used.
Check out the feature in action on Codepen
https://codepen.io/timeax/pen/OJrOJXy
I forked the
alpine
repo and tweaked thex-data.js
file to achieve this feature.Beta Was this translation helpful? Give feedback.
All reactions