Why wasn't my request updating? #4678
sedronbyron
started this conversation in
2. Show and tell
Replies: 1 comment
-
|
the bind will only update the attribute on the microtask queue, but the dispatch was causing it to trigger before that happened. |
Beta Was this translation helpful? Give feedback.
0 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.
-
Howdy ya'll, just started playing around with alpine + htmx and I think they work pretty cool together. I was struggling with something earlier today that I think would be helpful for other new people. Feel free to make suggestions or improvements if you wish.
The Goal
Make a pagination feature that sends a request for the next page of data when the next button is clicked. I would like for the only thing going over the network is the list of data, and for alpine to store client side state.
Initial Try:
Yay! HTMX is correctly updating the calls as the plus/minus buttons are pressed! But wait, the count seems to be 1 request behind? It is requesting page 0 when i want to request page 1.
Final try:
I read that Alpine makes updates to the DOM Async, so the reason why the counter was increasing but the requests were a count behind was because the request got sent before alpine finished updating the parameter. Moving the dispatch event after htmx has updated state or using
$nextTickfixed this.Another solution I got to work was this:
I think the two key points that I got from this were:
$watchand$nextTick.x-bindon hx-vals. This syntax was foreign to me so it was good to understand that alpine can interpolate under ${} syntax.Beta Was this translation helpful? Give feedback.
All reactions