x-data with re-usable data does not support dash-case names #1752
Unanswered
seangwright
asked this question in
5. Bugs
Replies: 1 comment 5 replies
-
Dashes are not allowed in variable names, it's a js thing. For example, in vanilla js, you can't define |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The docs show how
Alpine.data('someName', () => ({ ... }))
can be used to supply data for an element withx-data="someName"
https://alpinejs.dev/essentials/state#re-usable-data
However there are requirements for
someName
- it cannot bedash-case
.I've created an example pen where Alpine fails to function for the whole page when an
x-data
attribute is assigned a string with a dash.https://codepen.io/seangwright/pen/YzVWEmo
Alpine.data()
continues to function if its called with a string with a dash, but the attribute causes things to crash.I've run into this locally and end up with the console error:
I notice that the following returns
undefined
whenexpression
is a dash-case string:This causes the following to throw the error because
obj
isundefined
:If dash-case strings aren't supported for
x-data
, that's not a huge problem, but the docs don't mention it and I thought the error was caused by my use of Alpine as an ES module in a webpack bundle.Beta Was this translation helpful? Give feedback.
All reactions