Set root after mount for SSR
See original GitHub issueI’m using Next.js and I’d like to set root to a specific element.
window
and document
are only accessible after mount.
Is there an SSR-friendly way to wait until the component is mounted to set root?
Note: useEffect
fires only after mount.
// this won't work; document not defined
const { ref, inView } = useInView({
root: document.querySelector(".myroot"),
});
useEffect(() => {
if (inView) {
doSomething();
}
}, [inView, doSomething]);
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to change owner of mount point - unix - Server Fault
So mount /var/lib/mysql then chown mysql.mysql /var/lib/mysql . This will change the permissions of the root of the MySQL DB filesystem.
Read more >Server-Side Rendering (SSR) - Vue.js
Teleports require special handling during SSR. If the rendered app contains Teleports, the teleported content will not be part of the rendered string....
Read more >NextJS Track Mounted Components in SSR - Stack Overflow
I have dig into this and my feeling is that this is not possible for multiple reason. The setState update is async and...
Read more >React 18 introduces new root API ( ReactDOM.createRoot )
React 18 adds the new root API that comes up with the new out-of-the-box improvements.
Read more >A beginner's guide to React Server-Side Rendering (SSR)
In this lesson, we are going to talk about server-side rendering (SSR), its benefits, and its pitfalls. Then we will set up a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks! I got it working in v1 and v2. I used two observers for v1, one above the target div. When that is hidden but the target is visible, I achieve my goal.
https://f4rwj.sse.codesandbox.io/ https://codesandbox.io/s/competent-cohen-f4rwj?file=/pages/index.tsx
You could use the new Intersectionobserver v2. Support is still limited https://caniuse.com/intersectionobserver-v2
Otherwise it might make sense to look at the scroll position?