Force component to re-render (like Livewire $refresh) #4319
-
ProblemLivewire has a My use case is I have an element that is toggled with <div
x-data
x-show="someConditionInvolvingViewportSize">
</div> I thought it might be possible to use the new Resize plugin to trigger a re-render, but it don't think anything like this exists: <div
x-data
x-resize.document="$refresh()"
x-show="someConditionInvolvingViewportSize">
</div>
<!-- My condition uses `window.matchMedia`, which is why I don't need the dimensions provided by Resize --> Is there another way? WorkaroundI found this works, but it would be great if there was a more official way to do it: <div
x-data="{ tick: 1 }"
x-resize.document="tick++"
x-show="tick && someConditionInvolvingViewportSize">
</div> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You need observable variables (something from x-data or something using Alpine.reactive) to have reactive directives in Alpine so the correct way to do it is <div
x-data="{ show: false }"
x-resize.document="show = someConditionInvolvingViewportSize"
x-show="show">
ok
</div> |
Beta Was this translation helpful? Give feedback.
You need observable variables (something from x-data or something using Alpine.reactive) to have reactive directives in Alpine so the correct way to do it is