skip to Main Content

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


  1. You can check if document or window exists. It does not exist on SSR.

    const isSSR = () => !document
    
    Login or Signup to reply.
  2. Simply if you want to check SSR, you can do below.

    if (typeof window === 'undefined') console.log("SSR")
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search