I have created a package which will be used in a CRA and a NextJS environment.
The package has a component, which sets attributes on body, html and title tags.
Actually I am using useLayoutEffect to set the attributes. But for a NextJS project those attributes should be set in SSR to create html with those attributes set.
When using useLayoutEffect there is flickering between firstpaint and first run of useLayoutEffect.
Is there a way to solve that problem? How about other frameworks when they use that package?
The project should not have NextJS as a dependency.
2
Answers
You can check if
document
orwindow
exists. It does not exist on SSR.Simply if you want to check SSR, you can do below.