Why Prefer Alpine.data() To Global Alpine Function Data Providers? #2172
-
The V3 documentation states that Alpine.data() should be preferred, but I can't find any explanation why. What are the benefits of Alpine.data() compared to global component functions? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There isn't any advantage other than very slightly polluting global scope less. In our project we choose not to use Alpine.data. We use TS with Snowpack for development and Webpack for production. So all the alpine components, etc live in that library scope. So I'd say it's preference thing at this point. If you don't want to pollute global scope and want short named references to your component code, Alpine.data is decent solution. |
Beta Was this translation helpful? Give feedback.
There isn't any advantage other than very slightly polluting global scope less.
In our project we choose not to use Alpine.data. We use TS with Snowpack for development and Webpack for production. So all the alpine components, etc live in that library scope.
So I'd say it's preference thing at this point. If you don't want to pollute global scope and want short named references to your component code, Alpine.data is decent solution.