Skip to content

Load Utterances Comments only after someone scrolls to the bottom of the post #486

Answered by thebuilder
deadcoder0904 asked this question in Q&A
Discussion options

You must be logged in to vote

Well, the useInView will never trigger if it's not assigned to an element, so:

{inView ? <div id={commentNodeId} ref={ref} /> : null}

Would never do anything, since you only assign the ref once it's inView (which would be never).
In this case, the simplest approach is to simply not set the commentNodeId before the trigger element is inView. Just make sure

useUtterances(inView ? commentNodeId : '')

Make sure the element is triggered when you want it, maybe by making it absolute, so it can have a size without affecting the layout.
You can look for the sentinel pattern, which is usually what's used when doing lazy loading. The "sentinel" being the trigger element.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@deadcoder0904
Comment options

@thebuilder
Comment options

Answer selected by deadcoder0904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants