Thanks a lot for your article.
I noticed one issue. It is requesting the same page multiple times. So, let me share my suggestion to solve this issue.
# posts/index.html.erb <div id="posts" data-controller="pagination" data-pagination-url-value="<%= posts_path %> " data-pagination-page-value="<%= 2 %>" data-pagination-request-value="false" > <%= render @posts %> </div>
// pagination_controller.js static values = { url: String, page: Number, request: Boolean, }; scroll() { if (!this.requestValue && this.scrollReachedEnd && !this.hasLastPageTarget) { this._fetchNewPage(); } } async _fetchNewPage() { const url = new URL(this.urlValue); url.searchParams.set('page', this.pageValue) this.requestValue = true; await get(url.toString(), { responseKind: 'turbo-stream' }); this.requestValue = false; this.pageValue +=1; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks a lot for your article.
I noticed one issue. It is requesting the same page multiple times. So, let me share my suggestion to solve this issue.