Alpine.store('key') is reactive, $store.key is not #4536
-
Edit: added an even simpler example. Hi, I've got a hard time understanding the (I'm only using this HTML code, there's no JS script except the Alpine library) <input type="text" x-model="$store.text">
<p>Using $store.text : <span x-text="$store.text"></span></p> <!-- this is NOT reactive -->
<p>Using Alpine.store('text') : <span x-text="Alpine.store('text')"></span></p> <!-- this is reactive --> Could you please explain what is the difference between the two methods ? Am I using Thanks Original example : <div>
<input type="radio" id="1" name="radio" value="1" x-model.fill="$store.radioValue" checked>
<label for="radio">1</label>
</div>
<div>
<input type="radio" id="2" name="radio" value="2" x-model.fill="$store.radioValue">
<label for="radio">2</label>
</div>
<div>
<input type="radio" id="3" name="radio" value="3" x-model.fill="$store.radioValue">
<label for="radio">3</label>
</div>
<p x-text="$store.radioValue"></p> <!-- this is NOT reactive -->
<p x-text="Alpine.store('radioValue')"></p> <!-- this is reactive --> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
They should both be |
Beta Was this translation helpful? Give feedback.
First paragraph in the documentation page about stores:
"You can use $store to conveniently access global Alpine stores registered using Alpine.store(...)."
;)